This code gives me 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’
$
Apart from the warnings, the code works as expected.
What should I do to not get the warnings on compilation (no compiler pragma tricks please)?
The exact type of
time_tdepends on your platform and OS. It’s still quite often 32 bit (eitherintorlong), not 64, and some even use floats. The correct thing to do is to read into a known-size integer (eitherintorlong long) and then assign the value to atime_tas a second step.