The information in this article applies to:
SYMPTOMSIn Microsoft C, using a nameless structure as a member of a structure causes a compiler error if the two structures both have members with the same name. C versions 6.x generate the error: In C/C++ versions 7.0 and later, the error is: The code sample below, when built as a C source file, reproduces the error. The same sample, built as a C++ source file, will not display this behavior. CAUSEThis is expected behavior, not a bug. When a nameless structure is used within another structure, the members of the nameless structure become members of the new structure. In the C language, the member names must be unique. MORE INFORMATIONSample Code
The second structure (s2) is effectively the following:
This illustrates that the member variable "a" is being redefined. Correctly
used nameless structures can provide a good technique for building
structures with similar data structure without having the complexity of
truly nested structures.
Additional query words: 8.0 8.0c 9.0 10.0 11.0 /Tp
Keywords : kbcode kbCompiler kbVC100 kbVC150 kbVC200 kbVC400 kbVC410 kbVC420 kbVC500 kbVC600 |
Last Reviewed: July 1, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |