This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
%d or %ld for datatype int?
- From: Rich Johnson <rich at shawmutav dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 22 Dec 2003 15:24:01 -0500
- Subject: %d or %ld for datatype int?
Hi folks--
I'm having trouble getting the following to compile cleanly on multiple
platforms. Both platforms are using gcc 3.3:
#include <sys/time.h>
#include <stdio.h>
int main(){
struct timezone tz;
struct timeval now;
gettimeofday (&now, &tz);
printf ( "%ld seconds into the epoch\n", now.tv_sec );
return 0;
}
"gcc -Wall ..." on OSX (10.2.8) reports:
test.c: In function `main':
test.c:8: warning: long int format, int32_t arg (arg 2)
where tv_sec is an "int32_t" which is an "int" which is a 32-bit integer
If I change the "%ld" to "%d", then compilation on a linux platform
reports:
test.c: In function `main':
test.c:8: warning: long int format, __time_t arg (arg 2)
tv_sec is a "__time_t" which is a "long int" which is a 32-bit integer.
What gives here? Do I have to explicitly cast the tv_sec to a "long
int" to get a clean compilation on both platforms?
It just seems odd that in both cases the warning boils down to
"warning: 32bit integer used where 32bit integer expected"
Thanks,
--rich