Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!stl!robobar!ronald From: ronald@robobar.co.uk (Ronald S H Khoo) Newsgroups: comp.lang.c Subject: Re: Declaring array. Is this ok ? Message-ID: <1990Nov14.091809.10991@robobar.co.uk> Date: 14 Nov 90 09:18:09 GMT References: <1990Nov13.193813.9459@zoo.toronto.edu> Organization: Robobar Ltd., Perivale, Middx., ENGLAND. Lines: 41 > == henry@zoo.toronto.edu (Henry Spencer) >> == aps@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@robobar.co.uk +44 81 991 1142 (O) +44 71 229 7741 (H)