Dav*_*eri 3 c gcc typeof gcc-extensions
我不明白为什么会这样:
/* gcc range extension */
__extension__ static int fn(int n)
{
switch (n) {
case 0: return 0;
case 1 ... 1000: return 1;
default: return -1;
}
}
Run Code Online (Sandbox Code Playgroud)
但这不是:
/* gcc typeof extension */
__extension__ static void fn(int n)
{
typeof(n) a = n;
printf("%d\n", a);
}
Run Code Online (Sandbox Code Playgroud)
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.)
Run Code Online (Sandbox Code Playgroud)
我知道我可以编译-std=gnu99以避免错误,但第一个使用-std=c99并使用扩展
Ant*_*nko 13
非ANSI兼容关键字不会被重新启用__extension__(唯一的影响__extension__是警告抑制-pedantic).__typeof__如果要在ANSI模式下编译,请使用.
| 归档时间: |
|
| 查看次数: |
6653 次 |
| 最近记录: |