Microsoft KB Archive/113112

{|
 * width="100%"|

BUG: Internal Compiler Error: MSC1.CPP, Line 585 or 581

 * }

Q113112

-

The information in this article applies to:


 * The C/C++ Compiler (CL.EXE), included with:
 * Microsoft Visual C++, versions 1.0, 1.5

-

SYMPTOMS
Compiling the sample code shown below causes the compiler to incorrectly generate one of the following error messages:

fatal error C1001 : internal compiler error

( compiler file 'msc1.cpp', line 585 )

-or-

fatal error C1001 : internal compiler error

( compiler file 'msc1.cpp', line 581 )

CAUSE
Partially initializing an array of structures that is a field of another structure (referred to as an "aggregate") causes the compiler to generate internal compiler errors. The compiler does not generate an error if using a .C file. The example shown below illustrates this:

  typedef struct Element {    int   field1; char *field2; }  ELEMENT; typedef struct Aggregate {    ELEMENT list[5]; }  AGGREGATE; Defining and initializing a variable using:

  AGGREGATE mylist = {  1, "one", 2, "two", 3, "three", 4, "four" };    // Internal compiler error C1001.

RESOLUTION
There are three workarounds to this problem:

  Use an array instead of a single variable. For example:      AGGREGATE mylist[] = { 1, "one", 2, "two", 3, "three", 4, "four" };  Initialize all the members in the aggregate. If possible, compile the file as a .C file instead of a .CPP file.

STATUS
Microsoft has confirmed this to be a problem with C/C++ versions 8.0 and 8.0c. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

This is not a problem in Visual C++ 32-bit Edition.

MORE INFORMATION
In C++, when an aggregate is initialized, the initializer is a list of brace-enclosed, comma-separated initializers for the members of the aggregate in increasing sequence or member order. This rule applies recursively to the members of the subaggregates if there are any. If fewer initializers are in the list than the members of the aggregate, then the remaining members are padded with zeroes of the appropriate types.

Sample Code
/* Compile options needed: /c typedef struct Element { int   field1; char *field2; } ELEMENT; typedef struct Aggregate { ELEMENT list[5]; } AGGREGATE; void main(void) { AGGREGATE mylist = { 1, "one" , 2, "two" , 3, "three" , 4, "four" }; } Additional query words: 1.00 1.50 8.00 8.00c

Keywords : kb16bitonly

Issue type : kbbug

Technology : kbVCsearch kbAudDeveloper kbCVCComp