g++
allows Variable Length Arrays (VLA) as an extension. The results of sizeof
operator on VLAs are interesting:
int main ()
{
char size = 20, a[10], b[size];
cout<<"sizeof(a) = "<<sizeof(a)<<endl; // sizeof(a) = 10, (can be used as template param)
cout<<"sizeof(b) = "<<sizeof(b)<<endl; // sizeof(b) = 20 !! (can't used be as template param)
}
In case of sizeof(b)
, is g++ not following the standard where sizeof
is evaluated only at compile time? Is sizeof
overloaded?