Provided you don't make any false assumptions about what the compiler is producing, you'll be fine.
No problems will occur by accessing the members of a struct by name, but if pointer arithmetic is employed there could be some issues.
Note that
sizeof
will always return the actual size of the struct and not the sum of the members making up the struct, so stepping to the next item in an array using pointers will always be safe as long the pointer is of the type of the struct or if the distance stepped is equal to the sizeof of the struct.
If, however, you're using offsets from the start of a struct to the address of a member you could run into problems. Consider the following struct:
struct my_struct
{
char a;
int b;
}
Such a struct could be padded by the compiler to something like:
struct my_struct
{
char a;
char padding;
int b;
}
Therefore, if you have a statement like:
my_struct ms;
accessing
b
by an offset of
sizeof(a)
from the start of,
&ms + sizeof(char)
, will not necessarily end up at the beginning of
b
.
Hope this helps.