[MPlayer-dev-eng] [PATCH] libvo: GGI driver update
Christoph Egger
Christoph_Egger at gmx.de
Thu Sep 8 23:54:03 CEST 2005
> Christoph Egger wrote:
> > "if (arg)" is wrong, because it compares against the _number_ != 0,
> > but arg is a pointer. See below.
>
> No zero is special, see C99 6.3.2.3.3:
>
> An integer constant expression with the value 0, or such an
> expression cast to type void *, is called a null pointer constant...
>
> if (arg) is not wrong. The C++ standard is more clear about this, as it
> type-converts to bool and there are clear rules about the conversion. It
> seems that C99 just says it's the same as (arg != 0), but by the above
> paragraph, 0 is clearly a legal null pointer constant. Off topic, but in
> C++ NULL is often just #define to 0 because (void*)0 cannot be implicitly
> converted to other pointer types.
bool is a new datatype in C, since C99. It has been backported from
C++. In C++, NULL was thrown away or is a just a #define to 0 to make
migration from C to C++ easier. The C++ standard says, the compiler
autodetects this and handles this right.
With the introduction of the bool type in C99, same counts for C
(if the compiler supports this - most compilers still support C99
_partially_).
Now the question is, what requires (or better prefers) mplayer?
C89 or C99?
If C89, then "if (arg != NULL)" is the only correct thing.
If C99, then "if (arg)" is fine with me.
Personally, I still prefer C89 for more portability,
because compilers still have no complete C99 support.
> > I already experienced many bugs that caused stack and
> > heap corruption just by mixing up pointers with numbers
> > - in particular on 64bit platforms.
>
> Yes, but not this one.
>
> > > It's not a bug unless it can possibly lead to wrong behavior.
> >
> > My understanding of what is a bug is more restrictive:
>
> if (arg) is a very common C idiom. IMO if (arg != NULL) is not any
> easier to read than if (arg).
See above.
--
Greetings,
Christoph
5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse für Mail, Message, More +++
More information about the MPlayer-dev-eng
mailing list