[comp.std.c] "[][]" revisited

rfg@paris.ics.uci.edu (Ronald Guilmette) (03/23/90)

Lots of people have sent me messages containing their opinions regarding
the legality or illegality of declarations like:

int (*foo)[][];

But none of these folks has yet produced the smoking gun, i.e. nobody
has cited any passage from the ANSI standard that *either* says that
this is illegal or that it is illegal.

GCC sez it's legal.

I have reports that one other "ANSI" C compiler sez that it is legal also,
but another "ANSI" C compiler says it's not.

Perhaps nobody will ever find any passage that either says "this is legal"
or that says "this is not" legal.  What's the interpretation in that case?
Are all things that are not expressly prohibited allowed?  Are all things
that are not expressly allowed prohibited?

Lemme throw out yet another kinda related question.  Which (if any) of the
following declarations are legal?

extern int two_d_1[][];		/* tenative make is OK? */
int two_d_2[][];
static two_d_3[];

void foobar ()
{
	extern int two_d_4[][];
	int two_d_5[][];
	static int two_d_6[][];

	/* ... other unspecified stuff, possibly including complete
	   declarations for the local scope objects...  */
}

OK.  I just thought of one more. The first person to tell me where (in the
standard) it sez that this is either legal or illegal wins a free pair
of curly-braces! (Good for either home or office use :-)

int two_d[][] = { { 1,2,3 }, { 4,5,6 }, { 7,8,9 } };

GCC doesn't like it.  I don't see a damn thing wrong with it.  Initialize a
3x3 matrix.  Why not?


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

nagel@ics.uci.edu (Mark Nagel) (03/23/90)

rfg@paris.ics.uci.edu (Ronald Guilmette) writes:

>Lots of people have sent me messages containing their opinions regarding
>the legality or illegality of declarations like:

>int (*foo)[][];

>But none of these folks has yet produced the smoking gun, i.e. nobody
>has cited any passage from the ANSI standard that *either* says that
>this is illegal or that it is illegal.

While not _the_ ANSI standard, take a look at K&R II, pp. 216-217.
An array declaration without a size specification is an incomplete
type.  An array may only be constructed from a complete type.  If
you think about how arrays are layed out in memory, you'll
understand why this must be true.
--
Mark Nagel
UC Irvine Department of ICS   +----------------------------------------+
ARPA: nagel@ics.uci.edu       | Six plus six equals fourteen for large |
UUCP: ucbvax!ucivax!nagel     | values of six -- Dave Ackerman         |