I'm not shure this will work.. my platform uses only 16 bit alignment: the 16bit values are stored on addresses so that addr % 2 == 0. Now, if my compiler places pStruct so that pStruct % 4 == 0, it's true that:
Code:
&( pStruct->c ) % 4 == 0
-----+-----
addr | var
-----+-----
0008 | a //(16b)
0010 | dummy1 //(16b)
0012 | b //(32b)
0016 | dummy2 //(16b)
0018 | c //(16b)
...
and so your way it's ok. But if my compiler places pStruct so that pStruct % 4 !=0 and pStruct % 2 == 0?
Code:
&( pStruct->c ) % 4 == 2
-----+-----
addr | var
-----+-----
0010 | a //(16b)
0012 | dummy1 //(16b)
0014 | b //(32b)
0018 | dummy2 //(16b)
0020 | c //(16b)
...
As you see, b is a 32bit field but is 16 bit aligned.
Cristian