[Asterisk-Dev] Re: asterisk/include/asterisk utils.h,1.46,1.47

Luigi Rizzo rizzo at icir.org
Sat Oct 29 15:24:16 MST 2005


On Sat, Oct 29, 2005 at 03:42:59PM -0500, Kevin P. Fleming wrote:
> Luigi Rizzo wrote:
> 
> > while you are at it, it is probably a good idea
> > to change by-value arguments to [unsigned] int rather than
> > short (or often even char's). The compiler will generally pass
> > them as int anyways, ops on non-native types are often
> > slower (assuming one cares), and using int enables one to use
> > more strict compiler checks which is _extremely_ useful.
> 
> In this particular case we are dealing with SLINEAR audio data, which 
> intentionally is stored in 'short' variable to match its native range. 
> Granted, a platform could define a 'short' as being longer than 16 bits 
> (or fewer), but no current common platforms do so and it's unlikely 
> future ones will do so. If that becomes an issue, we'll switch to 
> int16_t or something similar.

i am saying a different thing. If you pass an argument by value,
almost always the compiler passes it as a native integer type,
because of alignment issues of surrounding arguments.
This in turn results in an implicit cast (which you cannot avoid),
which is often flagged by -Wimplicit-cast and this prevents from
running with -Werror.

As this combination of compiler flags is extremely useful to detect
unwanted conversions, my suggestion woul dbe to use [unsigned] int arguments
when possible.

	cheers
	luigi



More information about the asterisk-dev mailing list