references to dereferenced null pointers

Raymond Dunn ray at philmtl.philips.ca
Fri Mar 16 06:47:58 AEST 1990


>In article <1623 at argus.UUCP> ken at argus.UUCP (Kenneth Ng) writes:
>>But, I was told that NULL is defined as always being the value zero.

All the things that have been said about NULL and 0 and the *internal*
hidden actual value perhaps being different are of course true.

Perhaps Kenneth was actually looking for a simpler answer though.  In any
program, you are free to use *any* value you like to represent *your* value
of the illegal pointer.

So long as you don't define NULL to be this, and so long as you don't pass it
to library routines and expect it to be equivalent to passing NULL, or
expect library routines to return that value, you will have no problems.

As an example you could define:

#define NOPTR(type) ((type *)-1)

and use for example NOPTR(char) within your own code with the restrictions
stated.  It is still of course legal to pass such a value to standard
routines, but if they process NULL gently, they probably wont process your
NOPTR gently, but will indeed generate an exception.
-- 
Ray Dunn.                    | UUCP: ray at philmtl.philips.ca
Philips Electronics Ltd.     |       ..!{uunet|philapd|philabs}!philmtl!ray
600 Dr Frederik Philips Blvd | TEL : (514) 744-8200  Ext : 2347 (Phonemail)
St Laurent. Quebec.  H4M 2S9 | FAX : (514) 744-6455  TLX : 05-824090



More information about the Comp.std.c mailing list