[LCP]Variable Length Arrays in C, support as per C89/C99 in gcc

Jack Lloyd lloyd at acm.jhu.edu
Tue Jul 9 03:23:07 UTC 2002


I believe that GCC will accept any non-conflicting extensions. Odd that it
doesn't give a warning though (are you compiling with "-W -Wall"?).
Complying with a particular standard merely means that any valid program in
that language is accepted by the compiler - since VLAs are completely
undefined by C90, it seems likely that GCC simply accepts it.

BTW, your code seems wrong. The variable named 'b' is just an int, so you
can't assign to or read from b[0], b[1], b[2] - presumably you meant to use
a[0], a[1], a[2] there?

If you're worried about writing pure ISO C code without extensions, the
best way to do it is try your code out with several different compilers -
there are a reasonable number of free ISO C compilers out there, actually.

-Jack

On Mon, 8 Jul 2002, Y Giridhar Appaji Nag wrote:

> Hi,
>
> I have a piece of code which looks like this ...
>
> ----------- listing begin ------------
>
> #include <stdio.h>
>
> int main()
> {
> 	int b = 10 ;
> 	int a[b] ;
>
> 	b[0] = 12 ;
> 	b[1] = 89 ;
> 	b[2] = 78 ;
>
> 	printf("%d, %d, %d\n", b[0], b[1], b[2]) ;
> }
>
> ----------- listing end ------------
>
> I expect that this would not work with the pure C89 compilers or
> when I give the -std=c98 (or -std=iso9899:1990) to gcc. But it
> looks like I am not correct (though "info gcc" says that giving
> the -std=c98 or -ansi or -std=iso9899:1990 would comply to C89)
>
> However, if I give the -pedantic option, I get a warning that
> says... "ISO C89 forbids variable-size array `b'" which is ok,
> but then what's with the above -std options?
>
> I tried this with gcc 2.95.3 as well as 2.96. Any clues? Am I
> doing something that is incorrect here?
>
> -best regards,
> Giridhar
>
> --
> Y Giridhar Appaji Nag       Giridhar.Nag[@t]ubinetics(.)co.in
>
> While one person hesitates because he feels inferior, another
> is busy making mistakes and becoming superior. -Henry C. Link
>
> > an individual are not necessarily those of UbiNetics
>
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List
>







More information about the linuxCprogramming mailing list