Structure Padding | C Programming Tutorial

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

This becomes especially important when working with embedded systems. This can allow for easier data transfer between external ic’s into structures by replicating the data format of the external ic registers.

Gigaclank
Автор

Currently dealing with a network interop nightmare because the vendor developers didn’t understand this and used memcpy to deserialize. Thanks for the refresher

mattmurphy
Автор

Some processors are only able to read word aligned addresses, so the padding is there so the CPU doesn't fault. That being said, great explanation.

shaunmorgan
Автор

Thank you for this information. Searching this topic influenced me to learn about assembly

MarcoAurelio-svtk
Автор

Wowwww It's Amazing. Thank you for such a beautiful tutorial.

nameless
Автор

I didn't know about this before. Thanks!

undeadpresident
Автор

Most of the other videos I watched just left it at #pragma pack(1) but you actually gave solutions that are useful aside the pragma

themannyzaur
Автор

Tanks, sir.
Another good explanation, in deep on back work the machine.
I need to learn more about #pragma.
Good day sir.

hasdrubal
Автор

I knew about struct padding from the first general purpose language I learned, Pascal. Pascal does something analogous called record padding.

I do have a question: when a struct is written to file, are the data elements analogously padded in the file? I can only guess indeed yes because of the block layout of memory on disc, SSD, tape (in the olden days of yore), etc.

Mnogojazyk
Автор

Thanks, I was wondering why a struct I made was 8 bytes instead of 6

person
Автор

I accidentally discovered this after working on na personal project on raspberry pico. What I was trying to implement a CanOpen communication protocol on the pico

sanfreful
Автор

How about a video on how to keep a relatively short global array in cache?

erbenton
Автор

3:34 why doesn’t it just read the bytes at addresses 1–4? that’s one read operation since the CPU reads 4 bytes at a time

minandychoi
Автор

With TSMC of Taiwan and their amazing 5 nm silicon technology with super high speed and super high memory density, programmers may be pardoned to set the CHAR then INT then CHAR in STRUCT, however I don't recommend that they should do that ! They should follow Kevin instructions.
Thank you Kevin.

fifaham
Автор

Great, video as always, , what IDE are you using?

kennedymunyao
Автор

So if the word size is 8 bytes (which I assume is true of the common "64 bit" CPUs), how would that affect your example with {char x; int y; char z}?From what you said I'm not sure if all fields would be padded to 8 bytes due to word size (24 bytes total), or padded to 4 bytes from the int being the largest field (12 bytes total), or all packed into one word since 6 bytes can fit in one word (8 bytes total)?

dukereg
Автор

Please answer,

#include<stdio.h>
Struct abc{
Int a;
Char b;
Int c;
}var;

Void main() {
Printf("%d bytes", sizeof(var));
}

Output : 12 bytes

Whereas i am expecting the output to be "16 bytes" [4bytes(for a)+1bytes(for b)+3bytes(padding)+4bytes(for c)+4bytes(padding)] coz my system is of 64bit and word size has to be of 8bytes.

EmpowerKnowledge
Автор

"ch-are" not "car".

ddstar