PRB: Nested Nameless Structs Can Cause C2020 Error in C (64686)
The information in this article applies to:
- Microsoft C for MS-DOS
- Microsoft C for OS/2
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++, 32-bit Editions 1.0
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Editions 4.2
- Microsoft Visual C++, 32-bit Editions 5.0
- Microsoft Visual C++, 32-bit Editions 6.0
This article was previously published under Q64686 SYMPTOMS
In 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:
C2030: 'varname': struct/union member redefinition.
In C/C++ versions 7.0 and later, the error is:
error C2020: 'varname' : 'struct' member redefinition
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.
CAUSE
This 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.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbcode kbCompiler kbprb KB64686 |
---|
|