- 论坛徽章:
- 0
|
回复 9# Monox
至少说明一个问题 你的gcc 和我的gcc 版本不一致。
我确实是按照你说的int val =0;加了这一句后,才出现iso c90这种警告。
但是为什么不加就不出警告呢?
原因,恐怕不是你说的。
我发完整的。- #include<stdio.h>
- #include<stdbool.h>
- int main()
- {
- fun();
- printf("\a");
- printf("%d",sizeof(long int));
- bool bRet = false;
- _Bool bRet2 = false;
- return 0;
- }
- void fun()
- {
- }
复制代码- gcc -o hello -Wall -g -pedantic -std=c89 -ansi hello.c
- hello.c: In function ‘main’:
- hello.c:5:5: warning: implicit declaration of function ‘fun’ [-Wimplicit-function-declaration]
- fun();
- ^
- hello.c:7:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
- printf("%d",sizeof(long int));
- ^
- hello.c:9:11: warning: unused variable ‘bRet2’ [-Wunused-variable]
- _Bool bRet2 = false;
- ^
- hello.c:8:10: warning: unused variable ‘bRet’ [-Wunused-variable]
- bool bRet = false;
- ^
- hello.c: At top level:
- hello.c:12:6: warning: conflicting types for ‘fun’ [enabled by default]
- void fun()
- ^
- hello.c:5:5: note: previous implicit declaration of ‘fun’ was here
- fun();
- ^
复制代码 看到没,是没有你说的不支持_Bool
gcc --version
gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
Copyright (C) 2013 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.
顺便说一句,我有2台机器,第2台机器 出现了“warning: ISO C90 forbids mixed declarations and code”(注意,我并没有添加int val)
gcc版本:
gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
总结: gcc并没有很良好的支持所谓必须把变量的定义放在函数开头那里。
c89确实规定了,必须放在函数开头。
|
|