简体   繁体   English

为什么在 Windows 上运行的 Clang 没有 C 一致性(__STDC__ 未定义为 1)?

[英]Why Clang running on Windows has no C conformance (__STDC__ is not defined to 1)?

Sample code (t127.c):示例代码(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;
}

Invocation:调用:

$ 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

Questions:问题:

  1. Why Clang running on Windows has no C conformance ( __STDC__ is not defined to 1)?为什么在 Windows 上运行的 Clang 没有 C 一致性( __STDC__未定义为 1)? Ie what are the (technical) obstacles, which prevent "Clang running on Windows" to define __STDC__ to 1?即,阻止“在 Windows 上运行 Clang”将__STDC__定义为 1 的(技术)障碍是什么?
  2. Which extra options need to be specified to make Clang C conformant on Windows?需要指定哪些额外选项才能使 Clang C 符合 Windows?

It turns out that the definition of __STDC__ depends on clang's distribution.事实证明, __STDC__的定义取决于 clang 的分布。

@MM @毫米

works fine for me, target x86_64-w64-windows-gnu.对我来说很好,目标是 x86_64-w64-windows-gnu。 Sounds like you are using a non-conforming build, perhaps you could file a report with wherever you got this build from听起来您正在使用不合格的构建,也许您可以在从任何地方获得此构建的地方提交报告

Thanks for the confirmation an for the idea.感谢您对这个想法的确认。

In the test above clang version 11.0.1 was used.在上面的测试中使用了clang version 11.0.1 It was obtained from LLVM-11.0.1-win64.exe , which is shipped at https://github.com/llvm/llvm-project/releases/tag/llvmorg-11.0.1 .它是从LLVM-11.0.1-win64.exe获得的,它在https://github.com/llvm/llvm-project/releases/tag/llvmorg-11.0.1中提供。

In comparison clang installed via Cygwin installer ( setup-x86_64.exe ) shows C conformance:相比之下,通过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

@Clifford @克利福德

What happens if you change the test to #if STDC == 1 ||如果将测试更改为 #if STDC == 1 || 会发生什么defined STDC_VERSION ?定义STDC_VERSION

#if __STDC__ == 1 || defined __STDC_VERSION__

Invocation:调用:

$ /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

So, by some (what?) reason clang version 11.0.1 from LLVM-11.0.1-win64.exe does not define __STDC__ to 1.因此,由于某些(什么?)原因,来自LLVM-11.0.1-win64.exe clang version 11.0.1没有将__STDC__定义为 1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM