Hacker News new | past | comments | ask | show | jobs | submit login

> Structures in C are not padded and they do not even hold any meta information, not even for the member names; hence during allocation, they are allocated the space just enough to hold the actual data.

I get that this is a simplification and that the point is there's no hidden metadata at runtime but this is dangerously badly worded. Structures in C can be padded, they just happen not to be in this particular case. All the fields are 4 bytes and they're on a 32bit platform so these particular structures will be packed.

That's not always going to be true however. For example, if you add something that isn't a pointer or an int. Or compile on a platform with 64bit integers and 32bit ints.

See also: http://www.catb.org/esr/structure-packing/




The fist member of a struct is guaranteed not to have padding before it according to the C spec, so for this use case this is always true. Implementations are free to have padding in other places, but pretty much all implementations adhere to a ABI, and that forces the padding to be well defined.


You mean 64 bits pointers and 32 bits integers, I guess.


You're right, thanks. I'd edit but it's too late now.


You're thinking of struct members, not structs




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: