Reputation: 661
Is there a standard macro to check support of variable length arrays in C code? It it enough to check for c99 (__STDC_VERSION__ >= 199901L
) in all widely used compilers?
Upvotes: 4
Views: 554
Reputation: 34829
From the C11 specification §6.10.8.3
The following macro names are conditionally defined by the implementation:
[...]
__STDC_NO_VLA__
The integer constant 1, intended to indicate that the implementation does not support variable length arrays or variably modified types.
So if __STDC_VERSION__ > 201000L
you need to check __STDC_NO_VLA__
.
Otherwise, if __STDC_VERSION__ >= 199901L
VLAs should work, but you'll get a compile time error if the compiler is non-compliant.
Upvotes: 8