Laz*_*zer 5 c gcc compiler-warnings
这段代码给了我警告:
$ 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’
$
Run Code Online (Sandbox Code Playgroud)
除了警告之外,代码按预期工作.
我该怎么做才能在编译时得到警告(请不要编译编译器技巧)?
具体类型time_t取决于您的平台和操作系统.它仍然是相当频繁的32位(或int或long),而不是64,有的甚至是用浮动.正确的做法是读入已知大小的整数(int或者long long),然后将值time_t作为第二步分配给a .