Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: diamond@jit533.swstokyo.dec.com (Norman Diamond)
Subject: Re: strcat(foo,NULL) core dumps on Ultrix
Date: 12 Jun 91 06:20:45 GMT	[thread overview]
Message-ID: <1991Jun12.062045.13467@tkou02.enet.dec.com> (raw)
In-Reply-To: 1991Jun12.040043.24091@bronze.ucs.indiana.edu

In article <1991Jun12.040043.24091@bronze.ucs.indiana.edu> lwm@bronze.ucs.indiana.edu (Larry Meehan) writes:

[First an explanation of why dereferencing NULL is illegal, which was correct,
but had not yet arrived at this site when I previously replied.  But then...]

>If you look in /usr/include/stdio.h, you will see that NULL is really just 0,
>so our programs are trying to access location 0

Sorry, but you can't see that from looking in /usr/include/stdio.h.
When a source program uses an integer constant 0 as a pointer, the compiler
must recognize it as a null pointer constant.  However, a null pointer
constant does not have to be address 0 at execution time.  If the source
program uses 0 for an integer, its binary value has to consist of 0-bits,
but for a null pointer it does not have to do so.

For example, in some implementations, a byte of storage might be allocated
somewhere and never used for anything legal, but the implementation will
use its address as a null pointer.  For another example, on some Intel
processors, it would be very nice to use address (some segment):FFFF as a
null pointer, so that the hardware would trap some illegal dereferences.
In these cases, a 0 in the source program, compiled to a null pointer
constant, accesses a location other than 0.

These topics come up frequently in newsgroups comp.lang.c and comp.std.c.

The C programming language is confusing in this and in other ways.  It was
not designed for friendliness to mortals.

>which is legal on a VAX,

No.  (Personal opinion, not the company's opinion.)
It was uncaught (usually) and benign (usually), but illegal since day 1,
even before K&R-1.

>but not on the MIPS implementation of Ultrix.

Not anywhere.  Well, hypothetically an implementation could define an
extension to the language, and the program would be legal on such an
implementation, but I don't think any real implementation specifies this.
--
Norman Diamond       diamond@tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
Permission is granted to feel this signature, but not to look at it.


  reply	other threads:[~1991-06-12  6:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-06-11 12:34 strcat(foo,NULL) core dumps on Ultrix Rob Gabbard
1991-06-12  4:00 ` Larry Meehan
1991-06-12  6:20   ` Norman Diamond [this message]
1991-06-12 21:41     ` Larry Meehan
1991-06-13  7:20       ` Norman Diamond
1991-06-12  4:12 ` Norman Diamond
1991-06-12  4:34 ` George Robbins
1991-06-12 17:05 ` Lance Franklin
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox