示例代码(t127.c):
#include <stdio.h>
int main(void)
{
int ret;
#if __STDC__ == 1
printf("Has C conformance to version ");
#if __STDC_VERSION__
printf("%ld", __STDC_VERSION__);
#else
printf("1989");
#endif
printf(" OR has no C conformance but __STDC__ is defined to 1\n");
ret = 0;
#else
printf("Has no C conformance\n");
ret = 1;
#endif
return ret;
}
调用:
$ clang t127.c -std=c11 -Wall -Wextra -pedantic && ./a.exe
Has no C conformance
# comparison with gcc
$ gcc t127.c -std=c11 -Wall -Wextra -pedantic && ./a.exe
Has C conformance to version 201112 OR has no C conformance but __STDC__ is defined to 1
$ clang --version
clang version 11.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
$ gcc --version
gcc (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ systeminfo
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.19041 N/A Build 19041
问题:
- 为什么在 Windows 上运行的 Clang 没有 C 一致性(
__STDC__
未定义为 1)?即,阻止“在 Windows 上运行的 Clang”定义__STDC__
为 1 的(技术)障碍是什么? - 需要指定哪些额外选项才能使 Clang C 在 Windows 上符合要求?