[Ffmpeg-devel] execl should be terminated with null _pointer_

Dave Dodge dododge
Wed May 11 10:21:22 CEST 2005


On Tue, May 10, 2005 at 12:07:31PM -0400, Rich Felker wrote:
> On Tue, May 10, 2005 at 01:01:41PM +0200, Erik Slagter wrote:
> > Looks like SunOS "ANSI C" compiler/suite that are ehrm... not fully
> > compliant. Prototypes that are no prototypes (K&R style) or prototypes
> > missing altogether.

Some of it may be legacy compatibility.  In the SunOS 4 days even some
standard library functions were missing.  It's probably also C90
rather than C99, with the older standard allowing more implicit
behavior.  As I recall, some of the old Sun system header files were a
real problem if you cranked up the warning levels on the compiler.
BTW on SPARC most arguments are passed through registers, so if you
mistakenly mixed prototyped and unprototyped calls to a function it
mostly worked anyway.  Unfortunately this could hide nasty bugs that
would show up when you tried to move the "working" code to some other
architecture.

> > I bet they also defined NULL to 0. I also bet they are not the
> > only one. Being ANSI C compatible according to the spirit seems to
> > be very difficult.

> Actually ANSI allows NULL to be either 0 or ((void*)0). AFAIK 0L is
> illegal.

0L is allowed.  ANSI just says NULL expands to "an
implementation-defined null pointer constant".  Any integer (not
necessarily "int") constant expression with value 0, or any such
expression cast to void*, qualifies.

So even ridiculous things like this are allowed:

  #define NULL (sizeof(char) - (unsigned short)1.5)

> I was just saying it's stupid to define NULL to 0 because it
> hides errors, not that it's noncompliant.

I agree it would be easier if ANSI had just forced NULL to expand to a
pointer type, to catch more coding problems.  They chose to keep 0 as
an option for backwards compatibility.  In the rationale they note
that even ((void*)0) doesn't always work, because pointers to
different types are not necessarily the same size.

For example if you have an unprototyped or variadic function that
expects a pointer-to-function argument, to be safe you have to cast
NULL to a function pointer type even if it already expands to a void*.

                                                  -Dave Dodge





More information about the ffmpeg-devel mailing list