Patch: New null_terminated attribute for C/C++

Fergus Henderson fjh@cs.mu.OZ.AU
Mon Oct 14 19:04:00 GMT 2002


On 14-Oct-2002, Joseph S. Myers <jsm28@cam.ac.uk> wrote:
> On 13 Oct 2002, Tom Tromey wrote:
> 
> > This patch adds support for a new `null_terminated' attribute, and
> > -Wnull-termination option to gcc.
> > 
> > Some functions, like execl, require a trailing NULL argument.  Here
> > the null argument must have pointer type, so in C++ this requires a
> > cast.  It is easy to forget to leave off the terminating NULL.  Also,
> > apparently there are cases where the user writes `0' instead of `NULL'
> > in C code, leading to a problem when moving to a machine where
> > sizeof(int)!=sizeof(void*).
> 
> And execle has an argument after the NULL argument, and maybe some
> functions take multiple such lists.  You need a more general design (that
> at least can handle execle).

I agree that it would be bad to add this feature as is, and then later replace
it with a different syntax that was needed to support the more general case.
So, even though I like this patch, I must reluctantly agree with Joseph S.
Myers here.  His point about testcases is also a good one.


> If something is terminated by a single NULL,
> it should also warn for multiple NULLs.

That is a nice idea, but I don't think it should be required for
acceptance of the patch.  The patch would be useful and an improvement
to GCC even if it didn't include this.  It can always be added later
by a separate patch if someone feels strongly enough about this to
implement it.

-- 
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.



More information about the Gcc-patches mailing list