Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rochester!pt!ius2.cs.cmu.edu!edw From: edw@ius2.cs.cmu.edu (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <1219@ius2.cs.cmu.edu> Date: Mon, 29-Jun-87 23:14:31 EDT Article-I.D.: ius2.1219 Posted: Mon Jun 29 23:14:31 1987 Date-Received: Sun, 5-Jul-87 20:20:48 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <926@argus.UUCP> Organization: Carnegie-Mellon University, CS/RI Lines: 53 In article <926@argus.UUCP>, ken@argus.UUCP (Kenneth Ng) writes: > In article <13008@topaz.rutgers.edu>, ron@topaz.rutgers.edu (Ron Natalie) writes: > > I have always wondered why people think NULL is more mnemonic than 0. > > -Ron > > It's not mnemonic, on some machines its just wrong. NULL is ***NOT*** > defined as zero on all machines. Therefore the software writen with > that assumption will not work on such a machine. More than likely > the machine will be blamed even though the writer of the software is > to blame. Yes, its a software problem, but its a problem with that C compiler. Sorry, but the C compiler is suppose to treat 0 as a special token in this case. Quote from K&R pg. 192 However, it is guaranteed that assignment of the constant 0 to a pointer will produce a null pointer distingushable from a pointer to any object. The concept is extended to comparison too. But as a save guard against implementations of C that don't adhere to this rule, one should use NULL. So to answer Ron's question, you use NULL instead of 0 because there are those implements of C (which are wrongly implemented) that don't treat 0 the way they should. > > > if((fd=open("foo",1)<0) > [edit] > > fd = open("foo", 1); > > if(fd == -1) > > Almost agreed: but if a negative return code other than -1 is returned > the code doesn't react the same. > I can think of no Unix system call that doesn't return -1 on error. So I would say that it's a pretty good bet that "if (call(...) < 0)" and "if (call(...) == -1)" will act the same in all cases. Though, one should always consult the man pages for return values if in doubt. > > Kenneth Ng: Post office: NJIT - CCCC, Newark New Jersey 07102 > uucp !ihnp4!allegra!bellcore!argus!ken *** NOT ken@bellcore.uucp *** > bitnet(prefered) ken@orion.bitnet -- Eddie Wyatt e-mail: edw@ius2.cs.cmu.edu terrorist, cryptography, DES, drugs, cipher, secret, decode, NSA, CIA, NRO.