qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [Qemu-devel] [PATCH 03/11] configure: Fix compiler wa


From: Peter Maydell
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 03/11] configure: Fix compiler warning in config.log (integer from pointer)
Date: Sat, 17 Dec 2011 14:09:16 +0000

On 17 December 2011 12:11, Stefan Weil <address@hidden> wrote:
> Am 17.12.2011 12:29, schrieb Peter Maydell:
>>> +  return s != (const char *)0;
>>
>> You don't need this cast, I think.
>
> Indeed, a quick test with gcc-4.4.5 shows no new warning when
> I remove the type cast. Are you sure that this works with all
> supported versions of gcc and any set of warning options?

Yes. Both 0 and (void*)0 are null pointer constants;
comparing explicitly for "if (ptr != 0)" is equivalent to
"if (ptr)"; qemu style prefers the latter but there are
a few of the former in the codebase, so practically speaking
we know it compiles fine.

> Normally NULL is used for this kind of code, but it needs
> stddef.h.

Only in some coding styles. NULL is just a convenience
macro if you like that kind of thing.

> Typically NULL is defined to be ((void *)0 for C
> (that's the reason why I used a type cast, too). Only for
> C++ it is defined without a type cast.

The C standard permits plain "0" as a definition of NULL.

> The type cast won't harm and is not in "normal" code,
> so it can be committed as it is. I also don't mind if it is
> removed by whoever commits it. If it is preferred that
> I send an updated patch, I'd use NULL with stddef.h
> (just to be safe).

We use plain 0 for a null pointer constant in various
existing tests in configure; this is simpler and avoids
dragging in stddef.h. I would prefer that.

-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]