Warning for unadorned 0 in varargs lists?
Joe Buck
Joe.Buck@synopsys.COM
Fri Aug 20 00:02:00 GMT 2004
On Thu, Aug 19, 2004 at 03:58:54PM -0700, Eddie Kohler wrote:
> Hi all,
>
> I habitually use "0" for a null pointer, which causes serious problems
> on 64-bit machines when passed to a varargs function.
>
> So an optional [i.e. no -Wall] GCC warning that complained when an
> unadorned, uncast "0" was passed to a varargs function would help me a
> lot, and probably others.
You are implicitly assuming that the 0 is really intended to be a pointer.
But there's
printf("FOO = %d", FOO);
where FOO is a macro that is defined to be zero. Also:
open("unreadable_file", O_CREAT, 0);
> Would such a warning be considered for inclusion in GCC? Or do people
> think it might generate too many false positives?
A warning would make sense if, rather than warning for all varargs
functions, the user only gets a warning for functions that definitely
expect pointers: execl, for example. It might be better to do this with
something like the format-checking attributes supported for printf-like
functions: that is, an attribute that says a varargs function's variable
arguments are all pointers, or something like that.
More information about the Gcc
mailing list