Skip to contentSkip to conversation

Fix definition of NULL

PATCH In review Stefan Weil 2 participants 2 messages Feb 6, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix definition of NULL

Hello,

the definition of NULL in dyngen-exec.h is correct for C++ but wrong for C. It results in a compiler warning.

My patch fixes it. Because Qemu does not support C++, I just used the C definition and did not try to support C++, too.

Regards
Stefan Weil

Fix declaration of NULL.

dyngen-exec.h +1 -1
Index: trunk/dyngen-exec.h
===================================================================
@@ -91,7 +91,7 @@
 extern int fputs(const char *, FILE *);
 extern int printf(const char *, ...);
 #undef NULL
-#define NULL 0
+#define NULL ((void *)0)
 
 #if defined(__i386__)
 #define AREG0 "ebp"
#1 lore raw

In message: <[email protected]>
Stefan Weil <[email protected]> writes:
: Hello,
:
: the definition of NULL in dyngen-exec.h is correct for C++ : but wrong for C. It results in a compiler warning. :
: My patch fixes it. Because Qemu does not support C++, : I just used the C definition and did not try to support : C++, too.

Actually, it is correct for C as well. "#define NULL 0" is a perfectly acceptable definition[*]. Your definition is also correct, since there are two valid NULL pointer definitions in 'C'. Which one you use will determine which class of errors you catch, but neither one will catch all errors.

which compilers is it generating warnings on and what are the warnings?

Warner

[*] C9x section 3.2.3 para 3 states:

[#3] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.

with a footnote that says NULL is defined in stddef.h.