被叫对象'时间'不是一个功能

时间:2015-01-31 05:07:16

标签: c time stdio

我使用一个非常简单的一行代码来获取ubuntu上C的当前时间,但是它给了我以下错误: Called object 'time' is not a function

代码是: int currentTime = (unsigned int)time(NULL);

这个错误完全没有意义,可能的原因是什么?

1 个答案:

答案 0 :(得分:6)

无法看到您的实际代码会让您感到困难,但首先,您需要确保已包含time.h以便声明该函数。

其次,您需要确保代码中没有其他的内容称为time

例如,此代码可以正常工作:

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

int main(){
    int currentTime = (unsigned int)time(NULL);
    printf("%u\n", currentTime);
    return 0;
}

代码:

#include <stdio.h>
int time;

int main(){
    int currentTime = (unsigned int)time(NULL);
    printf("%u\n", currentTime);
    return 0;
}

产生

testprog.c: In function ‘main’:
testprog.c:5:38: error: called object ‘time’ is not a function

在我的Debian框中,就像 Ubuntu一样,只有更好: - )