The ANSI C standard does not allow selective initialization of array elements (39310)
The information in this article applies to:
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 1.51
- Microsoft Visual C++ 1.52
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 2.1
- Microsoft Visual C++ 4.0
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q39310 SUMMARY
The ANSI C standard does not allow selective initialization of array
elements with the following syntax:
char MyArray[10] = {'a','b',,'d',,'f','g',,'i','j'};
This attempt at selective initialization is not correct and will
generate a "Syntax Error" at compile time as follows.
error C2059: syntax error : ','
The following two declarations will compile and are valid declarations
for Microsoft C version 5.1 and later:
- The initialization of all the elements of the array is as follows:
char MyArray[10] = {'a','b','c','d','e','f','g','h','i','j'};
- The initialization of the first characters in the array is as
follows:
char MyArray[10] = {'a','b','c','d','e'};
Modification Type: | Major | Last Reviewed: | 9/30/2005 |
---|
Keywords: | kbhowto kbinfo kbLangC KB39310 kbAudDeveloper |
---|
|