From: Ken J. <Ken...@ie...> - 2007-07-20 13:58:58
|
>From "C++: The Complete Reference", by Herbert Schildt, page 176: You cannot know, from machine to machine, whether the fields will run from right to left or from left to right; this implies that any code using bit-fields may have some machine dependencies. Other restrictions may be imposed by various specific implementations, so check the user manual for your compiler. A long time ago, I had two Windows C compilers that produced bitfields in opposite directions. I wasted a lot of time tracking down that 'bug'. So I no longer trust bitfields. I like bitwise operators better anyway. -Ken Jackson Hynek Sladky writes: > I think it is a bug because: > > struct { > unsigned short CCC:12; > unsigned short READ_BL_LEN:4; > } CSD; > ----> works as expected (2 bytes long) > > struct { > unsigned short READ_BL_LEN:4; > unsigned short CCC:12; > } CSD; > ----> works wrong (3 bytes long) > > I think that this should work the same way shouldn't it? > Unfortunately I need the second version... :-( > > Hynek Sladky |