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

Luigi Rizzo rizzo at icir.org
Sat Nov 5 02:42:16 MST 2005


On Fri, Nov 04, 2005 at 04:49:11PM -0600, Kevin P. Fleming wrote:
> Luigi Rizzo wrote:
> 
> > 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
> 
> I don't think I like either of these options; rather, let's come up with 
> some preprocessor magic to 'learn' what the correct format should be, 
> and define a macro containing the proper printf format string 
> (AST_TIME_T_FORMAT). Then:
> 
>    snprintf(buf, sizeof(buf), "This is the time " AST_TIME_T_FORMAT 
> "\n", time());
> 
> would do the correct thing.

hmmm, this would be a nightmare programmingwise, considering that
most of the time these conversions are used for debugging messages
put in in a rush.
There might be another alternative, which is to settle on a
reasonable type (again, int or long) and use a wrapper function
(possibly defined as a cast, or empty, or whatever) to
do the conversion.
I am rather open on the actual type, both are ok considering that
i don't think asterisk runs on 16-bit architectures, 32-bit time_t
are the standard now and good until 2037 where hopefully we will
not have the same codebase and asterisk 16.2.0 will have revised
its design guidelines multiple times.

I have quickly browsed the web for applicable standards but have not
found much useful:
http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html

says
"All of the types shall be defined as arithmetic types of an appropriate length, with the following exceptions:"...
and
  * time_t and clock_t shall be integer or real-floating types.

which opens up to even more trouble if some platform at some point
decides to implement time_t as a double.

> You mention that time_t is 'long' on FreeBSD 4.x; is that true even on 
> 64-bit architectures?

this i am not sure because it is in machine/* so it might well be
defined differently. Note though that the 64-bit support on FreeBSD
4.x is very limited and i doubt anyone uses it seriously.

In any case the current asterisk sources fail, with -Werror, on
both FreeBSD 4.11 and 6.0. I would be curious if linux compiles
them cleanly. Did anyone try ?

	cheers
	luigi

> Asterisk-Dev mailing list
> Asterisk-Dev at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-dev
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-dev



More information about the asterisk-dev mailing list