我想在源文件中检测所使用的编译器是否支持 static_assert
。
最佳答案
在 c11 中,static_assert
是一个扩展为 _Static_assert
的 assert.h
宏。
你可以只使用:
#include <assert.h>
#if defined(static_assert)
// static_assert macro is defined
#endif
请注意,某些编译器(例如 IAR)也有 static_assert
关键字扩展,即使它们不支持 C11。
如评论中所述,您还可以检查 c11:
#if (__STDC_VERSION >= 201112L)
// it is c11, static_assert is defined when assert.h is included
#endif
关于c - 如何检测编译器是否支持 static_assert?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25552852/