This is the mail archive of the gcc-patches@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: Patch: New null_terminated attribute for C/C++


On 14-Oct-2002, Jason Merrill <jason@redhat.com> wrote:
> On 14 Oct 2002 11:18:38 -0600, Tom Tromey <tromey@redhat.com> wrote:
> 
> >>>>>> "Per" == Per Bothner <per@bothner.com> writes:
> >
> > Per> I'd like a warning if the final argument is 0 rather than an explict
> > Per> null pointer (NULL or (TYPE*)0), since 0 is non-portable.  Does your
> > Per> patch do that?
> >
> > Yes.  It checks to make sure that the zero has pointer type.
> 
> This is inappropriate for C++, where NULL must have integral type.

I don't think it is inappropriate.

If foo() is a varargs function that expects its argument list to be
terminated by a null pointer, and the user writes
	
	foo(..., NULL);

then this code will do the wrong thing on some platforms, and so the
compiler should warn about it.  The correct way to write it is

	foo(..., (T *) NULL);

for the appropriate type T.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


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