Path: utzoo!utgpu!water!watmath!clyde!rutgers!mcnc!gatech!bloom-beacon!athena.mit.edu!eichin From: eichin@athena.mit.edu (Mark W. Eichin) Newsgroups: comp.lang.c Subject: Re: exit(-1), 0 is sometimes magic Summary: Right answer, wrong reasons Keywords: exit, zero, flaming Message-ID: <2305@bloom-beacon.MIT.EDU> Date: 16 Jan 88 11:39:46 GMT References: <502@cresswell.quintus.UUCP> <6935@brl-smoke.ARPA> <1179@wjvax.UUCP> <6983@brl-smoke.ARPA> <7208@ki4pv.uucp> <23160@cca.CCA.COM> <1843@bsu-cs.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: eichin@athena.mit.edu (Mark W. Eichin) Organization: Man, I'm Thirsty Lines: 43 Regarding Rahul Dhesi's comments on 0 not being a magic number: 1) Assuming NULL is zero (meaning it is a zero bitstring internally) is not correct, however casting 0 to a pointer, as in: if(*p){ do_something() } where (*p) is (*p != 0) which becomes (*p != NULL) is valid. The trick is the conversion of 0 to NULL; on Multics, NULL is a pointer into segment -1 with arbitrary offset; on Primes, it is something other non-zero bitmap. This gets hashed about here every 6 months, it seems. 2) Assuming that arrays start at 0 is straight out of K&R. However, you are then stuck with using C arrays. I had a large (50Klines) application where we started out with a custom implementation of arrays, with bounds checking and operator packages and other ``neat stuff'', and we ORIGINALLY had ARRAY_MIN == 1. It kept us honest... since after the 3d rewrite (aren't educational projects fun :-) we decided to change the Array package implementation and ARRAY_MIN was suddenly 0 again. I am glad we didn't start out with 0 and convert to 1 later, that would have been BAD... but with all of the fenceposts to keep track of, we had alot of references to BASE that were explicit, so the conversion went fairly smoothly. (With a real package layer, like C++ has, we would have had NO problems, but this was vanilla C...) 3) Assuming that Division by Zero is illegal is not implementation defined, since the implementation is specified as standard mathematics. Mathematicians use a special symbol for `that which division is not defined upon': 0. Why should C programmers do otherwise? :-) In any case, the original point (that zero is not a magic number) was correct (we are *almost* in violent agreement here) but some of the excuses were not correct; point 2 above bothered me enough to respond... the point being that some things that are specified, but are changeable anyway. Zero is *specified* in some places as the correct thing, so extracting it out as a symbol can clutter and confuse. The change in meaning of 0 as a value to exit(int status) under un*x and vms$exit() is from the original spec being o/s specific. Oh well... Mark Eichin SIPB Member & Project Athena ``Watchmaker''