typedefstruct _DCB
{
DWORD DCBlength; // sizeof(DCB)
DWORD BaudRate; // Baudrate at which running
DWORD fBinary: 1; // Binary Mode (skip EOF check)
DWORD fParity: 1; // Enable parity checking
DWORD fOutxCtsFlow:1; // CTS handshaking on output
DWORD fOutxDsrFlow:1; // DSR handshaking on output
DWORD fDtrControl:2; // DTR Flow control
DWORD fDsrSensitivity:1; // DSR Sensitivity
DWORD fTXContinueOnXoff: 1; // Continue TX when Xoff sent
DWORD fOutX: 1; // Enable output X-ON/X-OFF
DWORD fInX: 1; // Enable input X-ON/X-OFF
DWORD fErrorChar: 1; // Enable Err Replacement
DWORD fNull: 1; // Enable Null stripping
DWORD fRtsControl:2; // Rts Flow control
DWORD fAbortOnError:1; // Abort all reads and writes on Error
DWORD fDummy2:17; // Reserved
WORD wReserved; // Not currently used
WORD XonLim; // Transmit X-ON threshold
WORD XoffLim; // Transmit X-OFF threshold
BYTE ByteSize; // Number of bits/byte, 4-8
BYTE Parity; // 0-4=None,Odd,Even,Mark,Space
BYTE StopBits; // 0,1,2 = 1, 1.5, 2
char XonChar; // Tx and Rx X-ON character
char XoffChar; // Tx and Rx X-OFF character
char ErrorChar; // Error replacement char
char EofChar; // End of Input character
char EvtChar; // Received Event character
WORD wReserved1; // Fill for now.
} DCB, *LPDCB;
What in the world is the meaning of the colon symbol followed by a number right after most of the early members, e.g., DWORD fBinary: 1;? I don't know what that means! In all my years of C coding I've never seen anything like that! I just checked the list of C operators and the colon symbol by itself isn't even an operator! At least not that I know of or ever saw. At best, its half of the scope resolution operator '::' or half of the conditional operator '?:'.
Also, I instantiated one of these in a simple console program and used the sizeof operator to printf its size, i.e. ...
What do you think I got? There are 16 DWORDs, each of which should be 4 bytes for 64 bytes total. Then there are 4 WORDs for 2 bytes each which brings up up to 72 bytes. Then there are 8 BYTEs or chars for 8 more which brings us up to 80 bytes. Instead of 80 bytes returned by sizeof(DCB) I'm getting 28!!!
What in the world is going on? I feel I'm in for a real lesson here! I can honestly say this is one of the strangest things I've ever seen! I'm completely bewildered! Help!
They are bit fields.
In the case of DWORD fDummy2:17; - this takes 17 bits.
If you add up all those bitfields - you will see that tey add up to 32.
They are 14 of those parameters - all show as being DWORD and would normally
take up 4 *14 = 56 bytes.
But they only take up 4 bytes.
Ah! Thanks guestgulkan. Never thought of that. I've used them in other languages, but never in C. I should be able to wrap my head around that now.
That syntax must be part of the definition of structs then? I was searching for C operators, and it doesn't show up there. When I first saw that I was thinking of the shift operators, which I don't use much, but that wasn't part of it.