This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Wrap up question regarding use of bitfields in structures.


Hi Akshay,
 
> Could anyone pls explain to me this behavior ?

I think it is best explained as GIGO.

Or as per ISO 14882 4.7.2:

If the destination type is unsigned, the resulting value is the least
unsigned integer congruent to the source integer (modulo 2^n where n is the
number of bits used to represent the unsigned type).

You can see the same kind of behavior by doing:

unsigned char c = 0x123456;

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]