小编Too*_*ote的帖子

在IF语句中定义的未定义变量出错

在尝试编译以下代码片段时:

#include <stdio.h>
#include <time.h>

void change_a(int * a) {
    *a = 1;
    return;
}

void main(void) {
    int a = 0;
    change_a(&a);
    if (a) {
        time_t start = time(NULL);
    }
/* do something that never mentions a */

    if (a) {
        time_t end = time(NULL);
       printf("Time spent = %ld\n", (int) end - start);
    }
}
Run Code Online (Sandbox Code Playgroud)

GCC声明该行中的start变量未定义printf:

$ gcc --version
gcc (Debian 4.8.2-1) 4.8.2
[SNIP]
$ gcc -o test.bin test.c 
test.c: In function ‘main’:
test.c:24:44: error: …
Run Code Online (Sandbox Code Playgroud)

c gcc gcc4.8

1
推荐指数
1
解决办法
644
查看次数

标签 统计

c ×1

gcc ×1

gcc4.8 ×1