gpt4 book ai didi

c - GCC 扩展类型

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

我不明白为什么会这样:

/* gcc range extension */
__extension__ static int fn(int n)
{
switch (n) {
case 0: return 0;
case 1 ... 1000: return 1;
default: return -1;
}
}

但这不是:

/* gcc typeof extension */
__extension__ static void fn(int n)
{
typeof(n) a = n;

printf("%d\n", a);
}

gcc 返回:

demo.c:14: warning: implicit declaration of function ‘typeof’
demo.c:14: warning: nested extern declaration of ‘typeof’
demo.c:14: error: expected ‘;’ before ‘a’
demo.c:16: error: ‘a’ undeclared (first use in this function)
demo.c:16: error: (Each undeclared identifier is reported only once
demo.c:16: error: for each function it appears in.)

我知道我可以使用 -std=gnu99 进行编译以避免错误,但第一个使用 -std=c99 并且还使用扩展

最佳答案

__extension__ 永远不会重新启用非 ANSI 兼容的关键字(__extension__ 的唯一效果是对 -pedantic 的警告抑制)。如果要在 ANSI 模式下编译,请使用 __typeof__

关于c - GCC 扩展类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14378714/

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