14.2 Using the NULL Constant

The symbolic constant NULL has different definitions for Windows and the Microsoft C Optimizing Compiler (CL). The WINDOWS.H header file defines NULL as follows:

#define NULL 0

On the other hand, the CL library header files (such as STDDEF.H) define NULL as follows:

#ifndef NULL
#define NULL ((void *) 0)
#endif

To avoid compiler warnings, you should use NULL only for pointers and handles. You should not use NULL for such data types as int and WORD.

You can avoid such compiler warnings by making sure that your application includes WINDOWS.H before any header file from the C run-time library that defines NULL, as shown in the following example:

#include <windows.h>
#include <stddef.h>

Because the header files in the C run-time library do not define NULL if it has already been defined, the preprocessor does not override the initial definition in WINDOWS.H.