KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q67037: Embedded Unnamed Structures and Unions Cannot Be Initialized

Article: Q67037
Product(s): See article
Version(s): 6.00 6.00a | 6.00 6.00a
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | buglist6.00 buglist6.00a | mspl13_c
Last Modified: 20-NOV-1990

The ability to utilize "nameless" structures and unions provides a
convenient shorthand for referring to structures embedded in other
structures, but the current design of the compiler does not allow
these unnamed members to be initialized.

Permitting initialization involves a number of ambiguities that the
compiler does not currently track. If you attempt to initialize a
nameless structure or union, the compiler will generate a "C2097 :
illegal initialization" error. The sample code below demonstrates this
limitation.

Microsoft has confirmed this to be a problem in C versions 6.00 and
6.00a and QuickC versions 2.50 and 2.51. We are researching this
problem and will post new information here as it becomes available.

Sample Code
-----------

typedef struct _reg {
    union {
        long   eax;
        short  ax;
        };
    union {
        long   ebx;
        short  bx;
        };
    } regtype;

regtype  foo = { {1l}, {2l} };    /* This initialization attempt
                                     generates a C2097 error     */

void main(void)
{
}

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.