# Thread: What do the colon and number mean in this struct definition?

1. ## What do the colon and number mean in this struct definition?

I was looking at this one struct definition in the Windows API, and several of the fields in the struct have a colon and a number after the field type and field name. What does that colon and number mean?

https://learn.microsoft.com/en-us/wi...inbase-comstat

Code:
typedef struct _COMSTAT {
DWORD fCtsHold : 1;
DWORD fDsrHold : 1;
DWORD fRlsdHold : 1;
DWORD fXoffHold : 1;
DWORD fXoffSent : 1;
DWORD fEof : 1;
DWORD fTxim : 1;
DWORD fReserved : 25;
DWORD cbInQue;
DWORD cbOutQue;
} COMSTAT, *LPCOMSTAT;

3. ## Re: What do the colon and number mean in this struct definition?

Originally Posted by Zvoni
COOL! I didn't know you could address individual bits in any programming language. I thought you needed to use bitwise arithmetic to isolate single bits or sets of bits within a byte. In Visual Basic 6 for example, to get the 5th bit (bit4) you would do:
Code:
'for a 1-bit bitfield starting on the 5th bit
bf1 = (bitfields\16) And 1

;for a 2-bit bitfield starting on the 5th bit
bf2 = (bitfields\16) And 3

4. ## Re: What do the colon and number mean in this struct definition?

Note that this c/c++ method for individual bits can only be used within a struct/class. Also, you have to be careful of endian layout and padding - especially if you're trying to match to eternal data.

5. ## Re: What do the colon and number mean in this struct definition?

Originally Posted by Ben321
COOL! I didn't know you could address individual bits in any programming language. I thought you needed to use bitwise arithmetic to isolate single bits or sets of bits within a b. In Visual Basic 6 for example, to get the 5th bit (bit4) you would do:
Code:
'for a 1-bit bitfield starting on the 5th bit
bf1 = (bitfields\16) And 1

;for a 2-bit bitfield starting on the 5th bit
bf2 = (bitfields\16) And 3
Look here (Freepascal/Delphi): https://www.freepascal.org/docs-html...ses/tbits.html

6. ## Re: What do the colon and number mean in this struct definition?

I'd add to this a note that if you're translating these to VB for use with APIs,

Code:
Public Type COMSTAT
dwBitfield As Long
cbInQueue As Long
cbOutQueue As Long
End Type
You add up the bits; they're not separate variables of which only 1 bit is used.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•