The information in this article applies to:
SYMPTOMSAttempting to initialize any element of a union except the first may generate any combination of the following compiler messages:
-or-
CAUSEThe 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. RESOLUTIONIf 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. MORE INFORMATION
EXAMPLE1.C, in the Sample Code below, fails compilation with one C2078
error and three C4047 warnings. The error is generated because only one
union element may be initialized (the first) and by the time the compiler
processes the "{ch1,ch2,ch3,ch4}" initialization, it has already filled
element one. The warnings are generated because the compiler expects to be
initializing "union TEST tsty" with integer values, but it is finding char*
(character pointers) instead.
Sample Code
REFERENCESFor additional information, please see the following article in the Microsoft Knowledge Base: Q47693 Initializing Unions Initializes First Member of the Union Additional query words:
Keywords : kbCompiler kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC400 kbVC500 kbVC600 |
Last Reviewed: July 6, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |