Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcvax!inria!axis!mickey From: mickey@axis.fr (Michael Dance) Newsgroups: comp.sys.ibm.pc Subject: Re: ** Re: MSC 4.0 Large Model ** Original Posters problem solved!!! Message-ID: <283@axis.fr> Date: Sat, 22-Aug-87 04:08:52 EDT Article-I.D.: axis.283 Posted: Sat Aug 22 04:08:52 1987 Date-Received: Sun, 23-Aug-87 21:41:44 EDT References: <10400006@altger.UUCP> <72@cunixc.columbia.edu> <1014@bsu-cs.UUCP> <4291@teddy.UUCP> Organization: Sharc Informatique Lines: 49 Summary: for those in love with 0 In article <4291@teddy.UUCP>, jpn@teddy.UUCP (John P. Nelson) writes: > >>> 1) Use NULL not 0 as often as applicable. > > > > This statement (always cast 0 for comparisons) is blatently UNTRUE! > It's just plain WRONG! The C language defines that the constant 0 can > be assigned to or compared against any pointer! The compiler may need > to recognize this as a special case (the standard does not insist that > a NULL pointer have a bit pattern of all zeros for instance). The "0" > MUST be promoted to a pointer, not the other way around. > > MORE disinformation! NULL is equivalent to 0, and is not "guaranteed" > to work any better than the constant 0. > > To summarize: when passing a null pointer to a function, you should > always cast the 0 or NULL to the proper pointer type. In any other > context, you may use 0 or NULL interchangably. Despite the assertions of the last poster I would like to point out that there are other systems than MSDOS and other compilers than Lattice and Microsoft. Kernighan and Ritchie introduced NULL (one assumes) for the simple reason that pointers are not the same as interges (nor shorts, longs etc) If you use NULL the correct value will always be used. For exeample, someone in this discussion said that MSC 4.0 uses 0L in Huge model (Large?) and 0 in other models. This is because pointers include a segment address + within segment offset making 4 bytes, in this case passing 0 instead of 0L passes a 2 byte integer value 0, the routine receiving this will look for a 4 byte value of 0, the missing 2 bytes will be the next 2 bytes on the stack (on most m/cs) which could be anything but have little chance of being 0. So for functions NULL is the correct thing to pass, this should be cast to the correct type if the type is not char * as other pointer types may be treated differently on different machines (eg alignment) As for assignment defined to work with 0 or NULL, this may be true but char *fred = NULL; is clearer than using 0 and only needs 3 extra key-presses so it is surely preferable. Certain machines (eg Motorola sv6350) NEED (char *)0 so NULL is shorter to type. Moral: in general, but not always, things such as NULL may be optional but were defined to avoid the programmer needing to be aware of differences in machine architecture, if you dont use them thats OK but your programs may only work on the machine on which you wrote them