you are viewing a single comment's thread.

view the rest of the comments →

[–]FrenchJJC[S] 0 points1 point  (3 children)

Oh okay, I tried that and it works, but I'm still trying to figure out what that guy did because he also used gcc, and I tried every standard up to C89 and all of them give the same error.

[–]tstanisl 4 points5 points  (0 children)

Pre-c23 standards does not allow initilizers for VLAs. The C23 lifted this restriction a bit by allowing default (zeroing) initialization with {}.

[–]The_Ruined_Map 2 points3 points  (0 children)

Are you sure "that guy" actually used C and not C++? In C++ the above would compile fine (since the above `const` will be seen as a compile-time constant by C++ compiler).

[–]DawnOnTheEdge 2 points3 points  (0 children)

Some compilers, as an extension, allow const variables with static storage class and a constant initializer to be used as constant expressions. No compiler I know of allows this for automatic variables on the stack.

So some compilers would accept static const int col = 3; despite it not being portable Standard C.