INFO: Initializing Bitfields as Integers in C (60252)
The information in this article applies to:
- Microsoft C for MS-DOS
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 4.0
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q60252 SUMMARY
In Microsoft C, you can initialize the values of an entire bitfield
structure as an integer in several ways:
- Declare the bitfield structure as part of a union with an integer.
(This is the preferred method).
- Use an integer pointer by setting the pointer to the address of the
structure and then changing what the pointer points to.
- Enforce the bitfield type constraints to get a copy of the bitfield
into an integer variable.
For examples of these three methods, see below.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbcode kbinfo kbLangC KB60252 |
---|
|