Simple questions about array declarations
Doug Gwyn
gwyn at smoke.BRL.MIL
Tue Feb 27 06:17:59 AEST 1990
In article <25E833AA.15362 at paris.ics.uci.edu> rfg at paris.ics.uci.edu (Ronald Guilmette) writes:
-Does this mean that the following declaration is illegal?
- int array1[3] = { 1,2,3 }; /* size is known! */
No, array1 has object type.
-How about the following pair of declarations? Are these legal or illegal?
- extern int array2[3];
- int array2[] = { 1,2,3 }; /* size is known! */
array2 has object type.
-Now assuming that the above pair of declarations is legal, how about the
-following pairs? Are these legal?
- extern int array3[4]; /* size = 4 words */
- int array3[] = { 1,2,3 }; /* size = 3 words! */
array3 has object type. Because you omitted the fourth initializer,
array3[3] starts off containing a 0 value.
- extern int array4[3]; /* size = 3 words */
- extern array4[] = { 1,2,3,4 }; /* size = 4 words */
array 4 has object type. You have specified too many initializers
and should get a diagnostic.
- extern int array5[4];
- int array5[3];
These types are not compatible; error.
- extern int array6[3];
- int array6[4];
Ditto.
- static int array7[];
- static int array7[3] = { 1,2,3 };
- static int array8[3];
- static int array8[3] = { 1,2,3 };
- static int array9[3];
- static int array9[] = { 1,2,3 };
- static int array10[];
- static int array10[] = { 1,2,3 };
All these are okay.
More information about the Comp.std.c
mailing list