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);

Right (and both cases are more serious than what I had thought of).


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.

This would generate the minimum number of false positives, but wouldn't catch a bunch of errors, or errors on most user functions. I'd be happy even with a version of the warning that required me to write "(int) 0" when I meant the integer zero (in varargs lists only).


Working on a patch for my own use: I don't know how to distinguish the tree for "(int) 0" from "0". Is there any difference?

Thanks,
Eddie


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