"[][]" revisited

Ronald Guilmette rfg at paris.ics.uci.edu
Fri Mar 23 11:35:01 AEST 1990


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