CentOS 上的 gcc 是否支持 C11,取决于你安装的 gcc 版本。
| CentOS 版本 | 默认 gcc 版本 | 是否支持 C11 | 说明 |
|---|---|---|---|
| CentOS 6 | 4.4.7 | ❌ 不支持 | 仅支持 C89/C99(部分) |
| CentOS 7 | 4.8.5 | ✅ 支持(实验性) | 需加 -std=c11 |
| CentOS 8 | 8.x / 9.x | ✅ 完全支持 | 默认支持 C11/C17 |
| CentOS Stream | 较新 gcc | ✅ 完全支持 |
即使 gcc 支持 C11,也通常需要显式指定标准:
gcc -std=c11 -o test test.c
若想启用 GNU 扩展版 C11:
gcc -std=gnu11 -o test test.c
_Atomic、threads.h 支持较弱)# 使用 SCL(Software Collections)
yum install centos-release-scl
yum install devtoolset-9
scl enable devtoolset-9 bash
gcc --version # 应为 9.x
gcc -std=c11 -dM -E - < /dev/null | grep __STDC_VERSION__
__STDC_VERSION__ 201112L → 支持 C11✅ 结论:
-std=c11)如果你告诉我 具体 CentOS 版本和 gcc 版本,我可以给你更精确的建议。