[MPlayer-dev-eng] [PATCH] cast null pointers

Reimar Döffinger Reimar.Doeffinger at gmx.de
Thu Aug 12 19:31:33 CEST 2010


On Thu, Aug 12, 2010 at 06:23:11PM +0100, Christopher Key wrote:
> Reimar Döffinger wrote:
> > On Thu, Aug 12, 2010 at 06:54:35PM +0200, Reimar Döffinger wrote:
> >   
> >> On Thu, Aug 12, 2010 at 04:56:49PM +0100, Edd Barrett wrote:
> >>     
> >>> Just a small stylistic note. Null pointers for execl should be casted to
> >>> pointer types. Pointed out to me by naddy@ (http://c-faq.com/null/null2.html):
> >>>       
> >> What a nonsense, the C99 standard (e.g. section 7.17) specifies NULL
> >> as a "null pointer constant", so it is required to be a pointer type.
> >> Some implementations may not conform to this, but unless you know
> >> of a specific one where this actually causes issues this is just
> >> obfuscation.
> >>     
> >
> > Hm, I managed to get myself confused by the language.
> > A "null pointer constant" is actually not required to be a "null
> > pointer" and thus to be of pointer type.
> > Seems somewhat silly to me, but well.
> >   
> There's no guarantee that the various pointer types are interchangeable,
> only that void* be large enough to represent any data pointer.  In
> pointer context, 0 will always work.  In a non pointer context, there's
> no guarantee that ((void *) 0) will do the correct thing, hence the
> requirement for an explicit cast.

It would work for most cases, which would be quite an advantage already.
I wouldn't mind so much if there was an actual _requirement_ for a cast,
or at least if there was a way to make gcc print a warning if NULL was
used in a non-pointer context without a cast, but as I see it there is
simply no really maintainable solution.


More information about the MPlayer-dev-eng mailing list