This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Warning for unadorned 0 in varargs lists?
- From: Joe Buck <Joe dot Buck at synopsys dot COM>
- To: Eddie Kohler <kohler at icir dot org>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 19 Aug 2004 16:33:40 -0700
- Subject: Re: Warning for unadorned 0 in varargs lists?
- References: <5855FB66-F233-11D8-AFB6-000A95A6D9BC@icir.org>
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.