Newsgroups: comp.os.minix
Subject: Re: Null pointers?
References: <7emn02$she$1@nnrp1.dejanews.com>
Organization: Rochester Institute of Technology, Rochester, NY
From: aje9383@osfmail.isc.rit.edu (Andrew Erickson)
NNTP-Posting-Host: grace.isc.rit.edu
X-Original-NNTP-Posting-Host: grace.isc.rit.edu
Message-ID: <371189da.0@isc-newsserver.isc.rit.edu>
Date: 12 Apr 1999 01:51:22 -0500
X-Trace: 12 Apr 1999 01:51:22 -0500, grace.isc.rit.edu
Lines: 41
XPident: aje9383
X-Original-NNTP-Posting-Host: 129.21.3.100
XPident: Unknown
Path: star.cs.vu.nl!newsfeed.amsterdam.nl.net!sun4nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-peer1.sprintlink.net!news-in-central.sprintlink.net!news.sprintlink.net!isc-newsserver.isc.rit.edu!aje9383
Xref: star.cs.vu.nl comp.os.minix:35182

In article <7emn02$she$1@nnrp1.dejanews.com>,  <dave_matthew@yahoo.com> wrote:
>The following code:
>
>int main(void)
>{
>	unsigned char *p;
>	p = 0;
>	*p = 0xff;
>	return 0;
>}
>
>does _not_ generate a segmentation fault on my IBM AT/8MHz running Minix
>2.0.2. Please tell me this is a problem with the compiler/OS (doesn't
>generate proper null pointers?) and not buggy hardware.
>
>David

I'd be inclined to think it's neither one.  A null (zero) pointer is simply
guaranteed to not point to anything you could want to point to; precisely
what sort of an effect dereferencing such a pointer has is, IIRC, completely
undefined.  (After all, the whole idea of a null pointer is something which
does not point to useful information.  0 is a special value which is
required by ANSI to be null--to not poiint to useful information--primarily
because things need to be able to specify a lack of information or storage
sometimes.)

On most UNIX systems, writing to a pointer whose value is zero will produce
a segmentation fault, but I'm not sure if this is even required by POSIX or
not.  This is primarily to aid programmers in catching writes to null
pointers.

As you found out, Minix does not do this, primarily because it cannot be
implemented on a number of Minix platforms--the 8088 and 68000 come to mind
immediately.  On a Minix 68K system, this program would probably change the
reset vector in RAM; this generally wouldn't accomplish too much, though,
since ROM is usually banked in over low RAM on a reset (and always on a
cold-start reset for obvious reasons.)  

--Andrew Erickson, aje9383@grace.isc.rit.edu


