This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ patch] accept __null as sentinel
Hi Joseph,
On Fri, 29 Apr 2005, Joseph S. Myers wrote:
> And in the process of such copy&pasting, many casts would likely already
> have been added.
Are you guessing or knowing? It's also done by looking at other source,
and doing only the difficult things in the same way.
> > what type, char* or void*? - Any? Who the hell designed this language?",
>
> To the correct pointer argument type used in the function calling va_arg.
It's a sentinel, remember? It's a null pointer. It's not interesting
which type it has, as it's only used to mark the end of a vararg list,
which is the point of the sentinel argument. All null pointers compare
equal, so in this case it's indeed completely useless to specify one.
> conversions from void * to other pointer types. Do these casual C++
> programmers not share the philosophy that allowing such silent conversions
> is a flaw in C?
Certainly not. Most of them are "do-what-I-mean" programmers, and have
limited knowledge for the details of type systems or loop holes in them.
So, as long as something works, they prefer a little non-strictness.
> So even if they think of NULL as a pointer it still needs the right
> type. It just so happens this isn't actually a case of C++ being
> stricter than C, but one where it's easier to detect the problem with
> the C++ compiler.
I agree partially. But in this case I fail to see the problem which
should be easier to detect. It's a delimiter. It has no type of it's
own. Hence no type is the inherently correct one (the _really_ correct
one depends on the actual interface used, which might be completely
opaque). It just so happens, that _we_ require it be a pointer type
(note, no special one), if you want to use this attribute. This was done
because it was observed that in fact, if an argument is used as limiter in
the way the sentinel attribut is supposed to check, it usually is of
pointer type. We could have also introduced the attribute where the
sentinel is marked by the property of being a short of value 42.
Obviously we chose an implementation which made more sense.
> > Would you be satisfied with moving it to -pedantic? I really don't want
>
> We don't have a documented extension that you can use NULL in this way, so
> [... and more ...]
Sigh. I knew it would be too hard to get this accepted, which is one
reason I submitted it so late. I wish more of the language lawyer and
purity fraction in GCC (which is becoming larger) would work for
distributors where real world (and some people may say invalid) code is
compiled in masses, not just one or two projects written by knowledgable
employees instead of hobbyists. This would provide a way of reality
check.
Ciao,
Michael.