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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With