我正在经历一个非常奇怪的问题gcc-4.7 (Ubuntu/Linaro 4.7.2-11precise2) 4.7.2.我没有警告就无法编译以下有效代码:
extern void dostuff(void);
int test(int arg1, int arg2)
{
int ret;
if (arg1) ret = arg2 ? 1 : 2;
dostuff();
if (arg1) return ret;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译选项和输出:
$ gcc-4.7 -o test.o -c -Os test.c -Wall
test.c: In function ‘test’:
test.c:5:6: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized]
Run Code Online (Sandbox Code Playgroud)
但是,以下代码编译时没有警告(虽然组装效率稍低):
extern void dostuff(void);
int test(int arg1, int arg2)
{
int ret;
if (arg1 && arg2) ret = 1;
if (arg1 && …Run Code Online (Sandbox Code Playgroud)