Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!mailrus!ames!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.std.c Subject: Re: references to dereferenced null pointers Message-ID: <23128@mimsy.umd.edu> Date: 16 Mar 90 03:28:49 GMT References: <51083@microsoft.UUCP> <25EB8EE8.8462@paris.ics.uci.edu> <1136@philmtl.philips.ca> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 35 In article <1136@philmtl.philips.ca> ray@philmtl.philips.ca (Raymond Dunn) writes: >... In any program, you are free to use *any* value you like to represent >*your* value of the illegal pointer. No, not really. >As an example you could define: > >#define NOPTR(type) ((type *)-1) The conversion from any integral constant other than zero to any pointer type is up to the implementation. Most often, this means that for any #define XXX ((mytype *)some_int_constant) you find two problems: the constant you picked happens to be equal to a valid pointer, and/or: the constant you picked causes the run time system to phone your mother and leave a nasty message on her answering machine. (Well, not really. :-) But something like `NOPTR(char)' may cause a run-time fault---a `bus error (core dumped)' sort of error.) Incidentally, the reason for the latter is that the system is allowed to trap as soon as an invalid pointer is examined or created. Again, the only solidly defined conversion from integral constant to pointer is for zero: the integral constant zero becomes, in a pointer context, a nil pointer of the appropriate type. (In addition, every nil pointer is in principle different, except for nil pointer to char vs. nil pointer to void.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris