Declaring array. Is this ok ?

Ronald S H Khoo ronald at robobar.co.uk
Wed Nov 14 20:18:09 AEST 1990


>  == henry at zoo.toronto.edu (Henry Spencer)
>> == aps at tut.fi (Suntioinen Ari)

>>I was wondering if following is legal in (ANSI) C:
>>int somefunc(int i)
>>{
>>	int  array[i]; /* Can I use i here ? */

>  No.  Array dimensions must be constant expressions, known at compile time.

>> Gcc seems to accept both.

> Gcc compiles an interesting language which is not ANSI C.

gcc compiles several different languages depending on what switches
you give it, viz:

	$ cat foo.c
	void foo(int i)
	{
		char bar[i];
	}
	$ gcc -c foo.c
	$ gcc -ansi -pedantic -c foo.c
	foo.c: In function foo:
	foo.c:3: warning: ANSI C forbids variable-size array `bar'
	$ 

Sure, it continues to produce a .o file, but isn't the diagnostic issued
above adequate to satisfy ANSI ?

As a matter of interest, is anyone keeping a publicly available list of
gcc's nonconformances ?  There seems to be a lot of "but gcc isn't conformant"
going round with little substantive data to back up that statement.
Sure, gcc currently doesn't have its own conforming library, but I don't
think that's the question being mooted here.

Moral: if you don't use the right compiler switches, you can even lead
prophets astray :-)
-- 
ronald at robobar.co.uk +44 81 991 1142 (O) +44 71 229 7741 (H)



More information about the Comp.lang.c mailing list