This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [c++] warn if NULL is passed through varargs
- From: Segher Boessenkool <segher at koffie dot nl>
- To: Michael Matz <matz at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 11 Oct 2002 02:23:15 +0200
- Subject: Re: [c++] warn if NULL is passed through varargs
- References: <Pine.LNX.4.33.0210101823310.9652-100000@wotan.suse.de>
> But I'm not even sure this
> alone is allowed to break passing NULL through varargs, _even_ if we have
> different pointers, because all null pointers of all types are required to
> compare equal, and furthermore can be converted to null pointers (and only
> to null pointers) of other types.
Yes, but it's the compiler's job to make sure this C requirement holds.
And the compiler can't do it in the case of passing NULL through varargs,
as it doesn't know the pointer's type.
See also the C FAQ, section 5.2
> Can someone come up with a non-conforming C program (with recognizable
> effects breaking the as-if rule) using NULL in varargs, when it is used
> only as "(void*)NULL"?
Any program doing this will suffice, on a machine where not all pointer types
have the same internal null pointer representation (as a bitpattern). Note
that this includes function pointers.
Segher