[Asterisk-Dev] Re: other -Werror issues - time_t printf format...

Tony Mountifield tony at softins.clara.co.uk
Fri Nov 4 15:31:16 MST 2005


In article <20051104141801.A62879 at xorpc.icir.org>,
Luigi Rizzo <rizzo at icir.org> wrote:
> so now i am hitting another batch of -Werror related problems,
> because in some places (res_features.c chan_iax2.c chan_sip.c
> and maybe 1-2 more places) printf uses a %ld format for time_t
> (and in some other places it uses %d).
> 
> On FreeBSD 6.x, time_t is __int32_t; on FreeBSD 4.x time_t is long.
> In both cases the size is 32 bit, but the compiler is not
> smart enough to understand that they are the same size and
> thus %ld and %d are perfectly equivalent -- or, seen from another
> perspective, the compiler is smart enough to understand that this
> cannot be generalized and thus it compilains.
> 
> Whatever explaination we chose what would be the preferred fix ?
> 1. cast the operand to int and always use %d
> 2. cast the operand to long and always use %ld

Since on most sane systems time_t is long, I would vote for option 2.
There could have in the past been systems where long is bigger than int,
but never the opposite.

Cheers
Tony
-- 
Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org



More information about the asterisk-dev mailing list