Обсуждение: compile warning in CVS HEAD
I get the following warning compiling CVS HEAD: [neilc:/Users/neilc/pgsql]% make -C src/backend/utils/error all [ ... ] gcc -no-cpp-precomp -O0 -Winline -fno-strict-aliasing -g -Wall -Wmissing-prototypes -Wmissing-declarations -I../../../../src/include -I/sw/include -c -o elog.o elog.c -MMD elog.c: In function `log_line_prefix': elog.c:1123: warning: passing arg 1 of `localtime' from incompatible pointer type This is on Mac OSX 10.3 w/ gcc 3.3 -Neil
Neil Conway <neilc@samurai.com> writes:
> I get the following warning compiling CVS HEAD:
> [neilc:/Users/neilc/pgsql]% make -C src/backend/utils/error all
> [ ... ]
> gcc -no-cpp-precomp -O0 -Winline -fno-strict-aliasing -g -Wall
> -Wmissing-prototypes -Wmissing-declarations -I../../../../src/include
> -I/sw/include -c -o elog.o elog.c -MMD
> elog.c: In function `log_line_prefix':
> elog.c:1123: warning: passing arg 1 of `localtime' from incompatible
> pointer type
Hm, looks like this code incorrectly assumes that the tv_sec field of
struct timeval is necessarily the same datatype as time_t. I'd suggest
assigning session_start into a local time_t variable.
regards, tom lane
Tom Lane wrote:
>Neil Conway <neilc@samurai.com> writes:
>
>
>>I get the following warning compiling CVS HEAD:
>>[neilc:/Users/neilc/pgsql]% make -C src/backend/utils/error all
>>[ ... ]
>>gcc -no-cpp-precomp -O0 -Winline -fno-strict-aliasing -g -Wall
>>-Wmissing-prototypes -Wmissing-declarations -I../../../../src/include
>>-I/sw/include -c -o elog.o elog.c -MMD
>>elog.c: In function `log_line_prefix':
>>elog.c:1123: warning: passing arg 1 of `localtime' from incompatible
>>pointer type
>>
>>
>
>Hm, looks like this code incorrectly assumes that the tv_sec field of
>struct timeval is necessarily the same datatype as time_t. I'd suggest
>assigning session_start into a local time_t variable.
>
*sigh*
my local (linux) man for gettimeofday says this:
struct timeval { time_t tv_sec; /* seconds */ suseconds_t tv_usec;
/*microseconds */ };
We could do what you say, or could we just cast it?
cheers
andrew
Andrew Dunstan <andrew@dunslane.net> writes:
> *sigh*
> my local (linux) man for gettimeofday says this:
> struct timeval {
> time_t tv_sec; /* seconds */
> suseconds_t tv_usec; /* microseconds */
> };
Yeah, but mine (HPUX) says that tv_sec is "unsigned long". I suspect
that on Darwin the types disagree as to signedness.
> We could do what you say, or could we just cast it?
If they really were different types (as in different widths) then
casting the pointer would be a highly Wrong Thing. I think copying
to a local is safer, even if it does waste a cycle or two.
regards, tom lane