Simple questions about array declarations

Ronald Guilmette rfg at paris.ics.uci.edu
Mon Feb 26 06:36:10 AEST 1990


I have several trivial questions about array declarations.  I'm just trying
to figure out what is considered legal based on sections 3.5, 3.5.4.2, and
3.5.7 of the December 1988 draft.

In section 3.5.7 it says:

	"The type of the entity to be initialized shall be an object type
	or an array of unknown size."

I do not understand what that last part of the sentence is trying to say.
Does this mean that the following declaration is illegal?

	int array1[3] = { 1,2,3 };	/* size is known! */

How about the following pair of declarations?  Are these legal or illegal?

	extern int array2[3];
	int array2[] = { 1,2,3 };	/* size is known! */

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! */

	extern int array4[3];		/* size = 3 words */
	extern array4[] = { 1,2,3,4 };	/* size = 4 words */


In the above example, the array sizes are apparently in conflict, but those
are cases where the conflict involves an array size which is derived
implicitly from an initializer.

How about the following examples, in which the array size conflicts do not
involve array sizes derived implicitly from initializers?  Are these legal
or illegal?

	extern int array5[4];
	int array5[3];

	extern int array6[3];
	int array6[4];

Finally, is there any legal way to "forward declare" a static-linkage array?
For example, are any of the following pairs of declarations legal?

	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 };


// Ron Guilmette (rfg at ics.uci.edu)
// C++ Entomologist
// Motto:  If it sticks, force it.  If it breaks, it needed replacing anyway.



More information about the Comp.std.c mailing list