C语言 如何在更高版本的 gcc 上启用 c11?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16256586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:12:00  来源:igfitidea点击:

How to enable c11 on later versions of gcc?

cgccc11

提问by Paul Baltescu

I currently use gcc 4.6.3. My understanding is that gccby default uses the gnu89standard and I would like to enable C11, the latest C standard. I tried:

我目前使用gcc 4.6.3. 我的理解是gcc默认情况下使用gnu89标准,我想启用最新的 C 标准 C11。我试过:

[pauldb@pauldb-laptop test ]$ gcc -std=c11 -o test test.c
cc1: error: unrecognised command line option ‘-std=c11'

I replaced c11with gnu11and I get the same error. What is the correct way to enable the latest C standard for gcc?

我替换c11gnu11,我得到了同样的错误。为 gcc 启用最新的 C 标准的正确方法是什么?

(Note: I'm interested in the latest C standard and not the latest C++ one.)

(注意:我对最新的 C 标准而不是最新的 C++ 标准感兴趣。)

回答by ouah

The correct option is -std=c11.

正确的选项是-std=c11

However, it is not available in gcc 4.6. You need at least gcc 4.7to have this option supported. In some older versions like gcc 4.6, the option -std=c1xwas available with experimental (i.e., very limited) support of C11.

但是,它在gcc 4.6. 您至少需要gcc 4.7支持此选项。在一些较旧的版本中,如gcc 4.6,该选项-std=c1x可用于 C11 的实验性(即非常有限的)支持。

Note that the current version of gccis gcc 8.2.

请注意,当前版本gccgcc 8.2.

回答by Janos

gcc 5.2.0 works with command line option ‘-std=c11'

gcc 5.2.0 使用命令行选项“-std=c11”

回答by KeshV

Just to let you know GCC 4.9.x has far more complete support than older versions. If you really need to use this feature, please switch to anything 4.8+ Here is the support status -- https://gcc.gnu.org/wiki/C11Status

只是为了让您知道 GCC 4.9.x 比旧版本具有更完整的支持。如果你真的需要使用这个功能,请切换到任何 4.8+ 这里是支持状态 -- https://gcc.gnu.org/wiki/C11Status

回答by rmstock

Inside a .spec file :

在 .spec 文件中:

%define gcc_ver %(if [[ $(gcc -dumpversion) > 4.7 ]]; then echo 1; else echo 0; fi)
# Do we use c11 ?
%if 0%{?gcc_ver} < 1
  %global std_c11 0
%else
  %global std_c11 1
%endif

# if the configure of the package supports it add :
%if %{std_c11}
  --enable-cxx11 \
%endif