My question is regarding the size of an array. As i know the size of an array must be a constant and it should be know at compile time. Off course my question is regarding char arrays, please have a look at the following code,
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
int i = 0;
for (; i<10; i++)
{
char a[i];
}
char b[i];
return 0;
}
According to my knowledge this code cannot be compiled, at least it should give a warning, but actually it dosen't. Is this because array-size-const rule is not applicable for char buffers, or some other reason. Can some one please explain the reason for this?
That is a compiler extension (that goes against the standard).
The -pedantic-errors flag (gcc) will produce the error:
ISO C90 forbids variable length array
ISO C++ forbids variable length array