[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gcc memory allocation
abel@bfr.co.il (Alexander L. Belikoff) writes:
> > void main()
> > {
> > int n=9;
> > int a[n];
> > }
> >
> 1. Constructs like int foo...; ...bar[foo] are allowed as GCC
> extensions.
Correct.
>
> 2. Certain flags (-ansi -Wall) make gcc complain about them.
Not -ansi and not -Wall (the former won't complain at all, the latter
will warn about "unused variable a"). The flag that you want to use is
-pedantic:
$ gcc -pedantic foo.c -o foo
foo.c: In function `main':
foo.c:4: warning: ANSI C forbids variable-size array `a'
The reason is clear from the gcc man page:
"The '-ansi' option does not cause non-ANSI programs to be rejected
gratuitously. For that, '-pedantic' is required in addition to
'-ansi'."
As for -Wall, the man page lists the -W flags that are included in
-Wall (NB: _not_ all -Wflags are enabled by -Wall!), and you will see
that -Wunused will react to the declared but unused a[n], but there is
none that would warn about variable array length.
--
Oleg Goldshmidt
BFM Financial Research Ltd.
goldshmt@netvision.net.il