Seleznev Anton
Seleznev Anton

Reputation: 661

Check support for variable length array in C

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

Answers (1)

user3386109
user3386109

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

Related Questions