-14 Apr 97 21:29:41-
=Alexander Derazhne babbled to All about About bit-field syntax=
AD> struct A { unsigned int x : 1, y : 2, z: 5; };
AD> struct B { unsigned int x : 1; unsigned int y : 2; unsigned int z : 5;
};
AD> A a; B b;
AD> === Begin Test.R ===
AD> sizeof A is 1
AD> sizeof B is 1
AD> === End Test.R ===
AD> Struct 'a' must contain all fields in one 'unsigned int', but it
AD> use only 1 byte (must be 4)! Struct 'b' is more strange: I need 3
AD> separeted 'unsigned int', but got 1 byte! IMHO, it's wrong: compiler
It's not wrong. You have told it that you only want one byte (exactly
8 bits up there!) when you put those colons in there. Try adding
another field or make one of those wider.
Also, you have declared exactly the same thing for A and B. When you
use a comma like that, it is just shorthand for what's in B.
AD> must use a separate places for it and corresponding size - this
That would completely defeat the purpose of bitfields.
AD> structure may be a mirror of hardware registers!
In which case it would have been even more inappropriate to ignore your
request that the struct be a bitfield. AH is hardly 96 bits wide.
AD> May be it's a bug of BCOS2 2.0 ?
Your compiler has several bugs, but this is not one of them.
Mike Phillips
INTERNET: phil4086@utdallas.edu
... Q: How do you deal with heavy traffic? A: Heavy psychedelics.
--- FMail/2 1.22
---------------
* Origin: oOo The Pit Viper oOo (1:124/2145)
|