This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warning for unadorned 0 in varargs lists?


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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]