TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALEXANDER DERAZHNE
from: ANTHONY TIBBS
date: 1997-04-18 16:47:00
subject: About bit-field syntax

On Apr 15 02:29, 1997, Alexander Derazhne of 2:463/16.100 wrote:
AD> #include 
AD> struct A { unsigned int x : 1,              y : 2,              z : 
AD> 5; };
AD> struct B { unsigned int x : 1; unsigned int y : 2; unsigned int z : 
AD> 5; };
AD> === Begin Test.R ===
AD> sizeof A is 1
AD> sizeof B is 1
AD> === End Test.R ===
Actually, if I understand this right, it is doing this properly.  The 
unsigned int only requires one byte of memory when using bitfields.
If you used:
struct A {unsigned int x, y, z;};
struct B {unsigned int x, y, z;};
Then yes, the compiler is wrong.
Think of it this way:  here is your "A" structure (memory wise - unsigned 
t)
FEDC BA98 7654 3210
.... ...Z ZZZZ  YYX
(I may be wrong - X may be at 'F', but I am not sure.)
You see, it still only uses one byte of memory.
Anthony
--- TriED 0.10 alpha 1
---------------
* Origin: World of Power BBS (1:163/545.15)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.