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

The first named element of a structure is required to be located at the same address as the structure, yes; but I'm not aware of any requirement beyond that.

Can you point me at the relevant paragraph?




Elements are required to be "sequentially allocated":

This is from the draft N1256 document as I don't have access to the official standard. From 6.2.5 - Types:

"A structure type describes a sequentially allocated nonempty set of member objects (and, in certain circumstances, an incomplete array), each of which has an optionally specified name and possibly distinct type"

I can say that a lot of device drivers in the Linux kernel depend on this ...


Hmm, I understood "sequentially allocated" to mean "this structure gets a block of memory and no other variables will be allocated space within that block". Your interpretation would make sense, though.

As for Linux device drivers... it wouldn't be the first time that the Linux kernel (and especially device drivers) assumed a certain compiler behaviour which wasn't guaranteed, with hilarious results on later compilers.




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

Search: