On 17 December 2011 12:11, Stefan Weil <s...@weilnetz.de> 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