Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mcnc!rti!xyzzy!throopw From: throopw@xyzzy.UUCP Newsgroups: comp.lang.c Subject: Re: char (*a)[] (was: Style [++i vs i++]) Message-ID: <253@xyzzy.UUCP> Date: Sat, 12-Sep-87 15:19:45 EDT Article-I.D.: xyzzy.253 Posted: Sat Sep 12 15:19:45 1987 Date-Received: Sun, 13-Sep-87 08:35:23 EDT References: <8298@brl-adm.ARPA> <587@cblpe.ATT.COM> <189@xyzzy.UUCP> <2310@mmintl.UUCP> <871@mcgill-vision.UUCP> <2348@mmintl.UUCP> Organization: Data General, RTP NC. Lines: 36 > franka@mmintl.UUCP (Frank Adams) > So does arithmetic on a null pointer produce undefined results? I don't > have a copy of the proposed standard available, so I don't know what it > says. This is about what it *should* say; if it doesn't, it should be > changed. The conclusion reached by several people I know who studied the wording on this point is that the standard does *NOT* say that arithmetic on the null pointer produces undefined results (contrary to my own interpretation). Most of them, however, agree that it *OUGHT* to make this undefined. > [it should be undefined because...] > So we have the general principle that pointer arithmetic should not be able > to adjust the value of the pointer outside the guaranteed "neighborhood" of > legal values near that pointer. > In the case of a null pointer, the only legal value in that neighborhood > is null itself; thus "(char *)0 + 1" produces an undefined result. > ("(char *)0 + 0" would be legal, and equivalent to "(char *)0".) I think this is not sufficent. The operation of adding zero to the null pointer should be illegal, because it is not a member of a neighborhood at all, let alone a neighborhood of one element. That is, the value "null" is not a member of an ordered set of addresses upon which arithmetic is meaningful. > As further evidence for this point of view, I note that there could be > machines where the hardware traps attempts to increment the null pointer. And there could be machines where the hardware traps attempts to add zero to the null pointer as well, so that should be undefined also. -- To understand a program you must become both the machine and the program. --- Alan J. Perlis -- Wayne Throop !mcnc!rti!xyzzy!throopw