Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!pa.dec.com!jrdzzz.jrd.dec.com!tkou02.enet.dec.com!jit533!diamond From: diamond@jit533.swstokyo.dec.com (Norman Diamond) Newsgroups: comp.sys.dec Subject: Re: strcat(foo,NULL) core dumps on Ultrix Keywords: null NULL Message-ID: <1991Jun12.062045.13467@tkou02.enet.dec.com> Date: 12 Jun 91 06:20:45 GMT References: <966@sdrc.COM> <1991Jun12.040043.24091@bronze.ucs.indiana.edu> Sender: usenet@tkou02.enet.dec.com (USENET News System) Reply-To: diamond@jit533.enet@tkou02.enet.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 43 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.