PRB: Initializing Non-Primary Union Element Produces Errors (39910)
The information in this article applies to:
- Microsoft C for MS-DOS
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++ for Windows, 16-bit edition 1.52
- Microsoft Visual C++, 32-bit Editions 1.0
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 5.0
- Microsoft Visual C++, 32-bit Editions 6.0
This article was previously published under Q39910 SYMPTOMS
Attempting to initialize any element of a union except the first may
generate any combination of the following compiler messages:
error C2078: too many initializers
warning C4047: 'initialization' - different levels of indirection
warning C4047: 'initializing' : 'type1' differs in levels of indirection
from 'type2'
warning C4133: 'initializing' : incompatible types - from 'type1' to
'type2'
CAUSE
The compiler issues these messages by design. According to the ANSI
standard, initialization of a union must be directed to the first element.
An attempt to initialize some other union member may be interpreted by the
compiler as a syntactically incorrect initialization of the first element.
RESOLUTION
If it is necessary to initialize a non-primary element of a union, change
the order of your union members, so that the element that requires
initialization appears as the first element of the union.
REFERENCES
For additional information, please see the following article in the
Microsoft Knowledge Base:
47693 Initializing Unions Initializes First Member of the Union
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbCompiler kbprb KB39910 |
---|
|