You're writing non-portable (non-correct) code!
GCC enables a number of extensions and supports a number of standards. Cool right? Well, almost. They allow newer features in even when you explicitly ask for support for an older standard, C89 for instance.
To quote the GGG man page:
The -ansi option does not cause non-ISO programs to be rejected gratuitously. For that, -pedantic is required in addition to -ansi. |
This means, if you want to enforce a particular standard, you have to use -pedantic along with -std=cNN. The other warning flags allow new features in.
Now all that's great until you attempt to recompile your code under a compiler that doesn't support all those lovely extensions.
As I recall, Ritchie was particularly annoyed about this particular point (allowing variable length arrays), but conceeded that he'd have to live with it because he hadn't made a fuss about it when it was initially proposed.
I am particularly annoyed about it because a pointer to an array is not the same as an array. There's an extra layer of indirection which your system programming language is now hiding.
My personal view is C89 was good enough.
restrict
is a reasonable addition because it follows in the tradtion of
register
to be a hint to the compiler. But I can't think of a justifyable reason to create a second C standard when C++ exists.
The reason I gave why posted code didn't compile is correct. And I hope I've shet some light on why rocketboy9000's code behaves differently.
Consider this example:
1 2 3 4 5 6 7
|
int main()
{
int sz = 3;
int array[sz];
return 0;
}
|
-ansi is the same as -std=89
1 2 3
|
$ cc -pedantic -ansi x.c -o x
x.c: In function `main':
x.c:4: warning: ISO C90 forbids variable-size array `array'
|
$ cc -pedantic -std=c99 x.c -o x