检查 C 中对可变长度数组的支持

Check support for variable length array in C

是否有标准宏来检查 C 代码中对可变长度数组的支持?它足以在所有广泛使用的编译器中检查 c99 (__STDC_VERSION__ >= 199901L) 吗?

来自 C11 规范 §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.

所以如果 __STDC_VERSION__ > 201000L 你需要检查 __STDC_NO_VLA__.

否则,如果 __STDC_VERSION__ >= 199901L VLA 应该可以工作,但如果编译器不兼容,您将收到编译时错误。