[asterisk-dev] rizzo: trunk r95069 - in /trunk/apps: app_ices.c app_queue.c app_voicemail.c
Tony Mountifield
tony at softins.clara.co.uk
Mon Dec 31 12:14:29 CST 2007
In article <20071227231316.70635A9DF61 at lists.digium.internal>,
SVN commits to the Digium repositories <svn-commits at lists.digium.com> wrote:
> Author: rizzo
> Date: Thu Dec 27 17:13:15 2007
> New Revision: 95069
>
> URL: http://svn.digium.com/view/asterisk?view=rev&rev=95069
> Log:
> NULL does not need to be cast to (char *)
This is not always correct. Sometimes it does, including in the first
example in question. See below:
> Modified:
> trunk/apps/app_ices.c
> trunk/apps/app_queue.c
> trunk/apps/app_voicemail.c
>
> Modified: trunk/apps/app_ices.c
> URL: http://svn.digium.com/view/asterisk/trunk/apps/app_ices.c?view=diff&rev=95069&r1=95068&r2=95069
> ==============================================================================
> --- trunk/apps/app_ices.c (original)
> +++ trunk/apps/app_ices.c Thu Dec 27 17:13:15 2007
> @@ -86,11 +86,11 @@
> close(x);
> }
> /* Most commonly installed in /usr/local/bin */
> - execl(ICES, "ices", filename, (char *)NULL);
> + execl(ICES, "ices", filename, NULL);
The prototype for execl is this:
int execl(const char *path, const char *arg, ...);
The NULL in question is part of the variable argument list, and so
it is not covered by an explicit prototype. In that case, it must
be cast to the desired type.
Without the case, if NULL is defined in the headers as 0 rather than
as ((void*)0), then it will be passed in as an int. If ints and pointers
are different sizes on the target architecture, this will result in stack
misinterpretation.
Please see the second main paragraph in http://c-faq.com/null/null2.html
and also http://c-faq.com/null/safermacs.html
In summary, a cast before a NULL function argument can only be omitted
when that argument has an explicit prototype.
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