🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1096

Re: references to dereferenced null pointers

#1096
From: Chris Torek
Date: Fri, 16 Mar 1990 03:28
35 lines
1883 bytes
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
Technical Details
Message-ID: <23128@mimsy.umd.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!mailrus!ames!haven!mimsy!chris
References: <51083@microsoft.UUCP> <25EB8EE8.8462@paris.ics.uci.edu> <1136@philmtl.philips.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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