【发布时间】:2010-11-13 07:35:17
【问题描述】:
这段代码给了我警告:
$ cat test.c
#include<stdio.h>
#include<time.h>
int main() {
time_t t;
scanf("%lld", &t);
printf("%lld\n", t);
return 0;
}
$ gcc test.c -o test
test.c: In function ‘main’:
test.c:7: warning: format ‘%lld’ expects type ‘long long int *’, but argument 2 has type ‘time_t *’
test.c:8: warning: format ‘%lld’ expects type ‘long long int’, but argument 2 has type ‘time_t’
$
除了警告之外,代码按预期工作。
我应该怎么做才能在编译时不收到警告(请不要使用编译器杂注技巧)?
【问题讨论】:
-
我会坚持使用 printf() 来查看 sizeof(time_t) 是什么,然后进行转换。通常 uint32_t 对我有用。
标签: c gcc compiler-warnings