[英]Shall a #pragma leading to nonstandard behavior cause __STDC__ macro not to be defined to 1?
[英]Why Clang running on Windows has no C conformance (__STDC__ is not defined to 1)?
示例代碼(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
問題:
__STDC__
未定義為 1)? 即,阻止“在 Windows 上運行 Clang”將__STDC__
定義為 1 的(技術)障礙是什么? 事實證明, __STDC__
的定義取決於 clang 的分布。
@毫米
對我來說很好,目標是 x86_64-w64-windows-gnu。 聽起來您正在使用不合格的構建,也許您可以在從任何地方獲得此構建的地方提交報告
感謝您對這個想法的確認。
在上面的測試中使用了clang version 11.0.1
。 它是從LLVM-11.0.1-win64.exe
獲得的,它在https://github.com/llvm/llvm-project/releases/tag/llvmorg-11.0.1中提供。
相比之下,通過Cygwin安裝程序 ( setup-x86_64.exe
) 安裝的 clang 顯示 C 一致性:
$ clang 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 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-unknown-windows-cygnus
Thread model: posix
@克利福德
如果將測試更改為 #if STDC == 1 || 會發生什么定義STDC_VERSION ?
#if __STDC__ == 1 || defined __STDC_VERSION__
調用:
$ /cygdrive/d/LLVM/11.0.1/bin/clang t127.c -std=gnu11 -Wall -Wextra -pedantic && ./a.exe
Has C conformance to version 201112 OR has no C conformance but __STDC__ is defined to 1
因此,由於某些(什么?)原因,來自LLVM-11.0.1-win64.exe
clang version 11.0.1
沒有將__STDC__
定義為 1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.