gpt4 book ai didi

c - C11 可选功能宏在哪里?

转载 作者:太空狗 更新时间:2023-10-29 15:24:13 24 4
gpt4 key购买 nike

在 C11 标准中,编译器应该提供一些宏来测试可选功能的存在。我可以在哪些标题中找到它们?

例如,__STDC_NO_VLA__ 位于何处?

使用 GCC,即,如果我试图在 complex.h 中找到 __STDC_NO_COMPLEX__,我在那里找不到它...

最佳答案

它们没有在任何头文件中定义,编译器会自己定义它们。

您可以转储所有预处理器定义。例如对于 gcc 写:

gcc -dM -E - < /dev/null

以我为例:

bob@bob-fedora:~/trunk/software$ gcc --version
gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
Copyright (C) 2012 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.

bob@bob-fedora:~/trunk/software$ gcc -std=gnu11 -dM -E - < /dev/null | grep STDC
#define __STDC_HOSTED__ 1
#define __STDC_UTF_16__ 1
#define __STDC_VERSION__ 201112L
#define __GNUC_STDC_INLINE__ 1
#define __STDC_UTF_32__ 1
#define __STDC__ 1

在您给出的示例中,__STDC_NO_VLA__ 的存在意味着编译器不支持可变长度数组。你可以这样写:

#ifdef __STDC_NO_VLA__
#error Your compiler does not support VLAs! Please use a supported compiler.
#endif

或者

#ifndef __STDC_NO_VLA__
// code using variable length arrays
#else
// fallback code for when they are not supported
#endif

关于c - C11 可选功能宏在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22914206/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com