time_t definition

Thomas D. Dean tomdean at speakeasy.org
Tue Jan 15 18:35:46 UTC 2013


I am attempting to recompile some code from an older version.

 > uname -a
FreeBSD ZD7000 9.1-STABLE FreeBSD 9.1-STABLE #1: Sun Jan 13 23:44:33 PST 
2013     root at ZD7000:/usr/obj/usr/src/sys/GENERIC  i386

 > make
gcc47 -O2 -pipe  -I../../include -std=gnu99 -fstack-protector 
-Wsystem-headers -Werror -Wall -Wno-format-y2k -Wno-uninitialized 
-Wno-pointer-sign -c data-collection.c
data-collection.c: In function 'main':
data-collection.c:214:4: error: format '%ld' expects argument of type 
'long int', but argument 3 has type 'time_t' [-Werror=format]
data-collection.c:234:4: error: format '%ld' expects argument of type 
'long int', but argument 3 has type 'time_t' [-Werror=format]
cc1: all warnings being treated as errors
*** [data-collection.o] Error code 1


 > cat data-collection.c
...
#include <time.h>            /* time_t */
#include <sys/time.h>        /* gettimeofday() */
...
         gettimeofday(&spi_stop, &tz); /     * line 211 */
           printf("Loop %d, SPI  %ld %ld\n",
                  loop,
                  spi_stop.tv_sec, spi_stop.tv_usec);
...
           gettimeofday(&disk_stop, &tz);    /* line 231 */
           printf("Loop %d, Disk %ld %ld\n",
                  loop,
                  disk_stop.tv_sec, disk_stop.tv_usec);
...

time.h defines time_t

#ifndef _TIME_T_DECLARED
typedef __time_t        time_t;
#define _TIME_T_DECLARED
#endif

sys/time.h includes sys/types.h which includes sys/_types.h which 
includes machine/_types.h where __time_t is defined

typedef __int32_t       __time_t;               /* time()... */

Question:  Why do I see the error?

Tom Dean


More information about the freebsd-questions mailing list