TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: RICK BISCHOFF
from: HERBERT BUSHONG
date: 1997-03-22 06:56:00
subject: Bit Fields

::> Does anyone know how to declare a variable that holds only one bit of
::> information.. (You know only two values (0 or 1)) ???
Many compilers allow you to define bit fields in structs (thats the only way 
I 
know to get *true* bit fields).
struct someStruct
{
   unsigned bit1 :1;
   unsigned bit2 :1;
   unsigned bit3 :1;
   unsigned bit4 :1;
   unsigned bit5 :1;
   unsigned bit6 :1;
   unsigned bit7 :1;
   unsigned bit8 :1;
};
The number after the : indicates how may bits that member uses, so for 1
bit, you would use :1   (I seem to recall some compilers had a problem if the
bit fields didn't add up to a multiple of 8??? but don't quote me on that 
>)
#  Herbert Bushong    harchon@centuryinter.net       [TEAM OS/2]    
-  Blackbeard's BBS   Intelec: 239:600/0            
+  Fido: 1:19/19      http://www.win.net/eunicecity/stltcc/hbush/
---
   RM 1.31 2508   Belly Dancers:   People who use sign language and stutter
---------------
* Origin: Blackbeard's BBS - Ville Platte, LA - 318-468-3385 (1:19/19)

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™.