Question 5.6

If NULL were defined as follows:

	#define NULL ((char *)0)
wouldn't that make function calls which pass an uncast NULL work?


Not in general. The problem is that there are machines which use different internal representations for pointers to different types of data. The suggested definition would make uncast NULL arguments to functions expecting pointers to characters work correctly, but pointer arguments of other types would still be problematical, and legal constructions such as

	FILE *fp = NULL;
could fail.

Nevertheless, ANSI C allows the alternate definition

	#define NULL ((void *)0)
for NULL. Besides potentially helping incorrect programs to work (but only on machines with homogeneous pointers, thus questionably valid assistance), this definition may catch programs which use NULL incorrectly (e.g. when the ASCII NUL character was really intended; see question 5.9).

References: Rationale Sec. 4.1.5


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback