F
Francine.Neary
Consider the following situation. I have a large static array s[] of
structs, say of size 500. I also need a smaller array of chars, say of
size 100, which has nothing to do with the struct.
To conserve memory, I'd like if possible to use (after checking with
offsetof and sizeof that there's enough padding to fit a char -
usually it will be) space between fields in the structs to store these
chars. If the padding is between fields s.a and s.b then I could take
my nth char to be at ((char *) &s[n].a)+sizeof(s[n].a).
For this to work, I'd need to know:
1) changing the padding bytes won't affect how the implementation
interprets the struct
2) the implementation won't overwrite padding bytes itself when
manipulating the struct
Are these things guaranteed?
structs, say of size 500. I also need a smaller array of chars, say of
size 100, which has nothing to do with the struct.
To conserve memory, I'd like if possible to use (after checking with
offsetof and sizeof that there's enough padding to fit a char -
usually it will be) space between fields in the structs to store these
chars. If the padding is between fields s.a and s.b then I could take
my nth char to be at ((char *) &s[n].a)+sizeof(s[n].a).
For this to work, I'd need to know:
1) changing the padding bytes won't affect how the implementation
interprets the struct
2) the implementation won't overwrite padding bytes itself when
manipulating the struct
Are these things guaranteed?