This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Wrap up question regarding use of bitfields in structures.
- From: John Love-Jensen <eljay at adobe dot com>
- To: Akshay Ranjan <akshay dot ranjan at gmail dot com>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Mon, 22 Oct 2007 06:18:50 -0500
- Subject: 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