"Eric J.Hu" <eh*@lucent.com> writes:
Such as I have following bitmap structure and assigned value:
struct bm
{
char high2bits:2;
char mid4bits:4;
char low2bits:2;
};
bm.high2bits = 3;
bm.mid4bits = 0;
bm.low2bits = 0;
The char value is 0x03 in little endian mode, and the char value is 0xc0
in big endian mode. How to eliminate the bitmap difference?
The only allowed types for bit-fields are int, signed int, unsigned
int (plain int may be either signed or unsigned in this context only)
and _Bool (C99 only). Your compiler may allow char bit-fields, but
it's non-portable. You probably want to use unsigned int.
Layout of bit-fields is implementation-specific. If you want
portability between little-endian and big-endian systems, don't use
bit-fields at all; use an unsigned integer type and manipulate the
bits yourself.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.