Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!panda!teddy!jpn From: jpn@teddy.UUCP (John P. Nelson) Newsgroups: comp.sys.ibm.pc Subject: Re: ** Re: MSC 4.0 Large Model ** Original Posters problem solved!!! Message-ID: <4291@teddy.UUCP> Date: Fri, 21-Aug-87 10:00:48 EDT Article-I.D.: teddy.4291 Posted: Fri Aug 21 10:00:48 1987 Date-Received: Sun, 23-Aug-87 00:44:41 EDT References: <10400006@altger.UUCP> <72@cunixc.columbia.edu> <1014@bsu-cs.UUCP> <3352@zen.berkeley.edu> Reply-To: jpn@teddy.UUCP (John P. Nelson) Organization: GenRad, Inc., Concord, Mass. Lines: 38 >>> 1) Use NULL not 0 as often as applicable. > >A cast is necesary for a comparison with large model pointers in >both lattice C and MSC4.0. If you don't cast, then the pointer will >be converted to an int, thereby loosing precision, and very likely >your program will have outlandish behavior. I can't believe how much BAD information gets posted here. If you don't know the answer, then DON'T POST!!!!! 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. I can state with authority that there is no BUG as listed above in MSC 4.0 (and it would definitely be a serious BUG). I cannot speak for Lattice compilers. >Using 0 is not usually >portable to compilers where sizeof(int) != sizeof(char *). Using >NULL is guaranteed to work. Someone mentioned why use NULL, since >stdio.h just defines it as 0. Well, both MSC and Lattice, define >NULL as 0 in small model, and 0L in large model. Not everyone >is lucky enough to work on a machine with pointers the size of ints. MORE disinformation! NULL is equivalent to 0, and is not "guaranteed" to work any better than the constant 0. The Lattice and Microsoft compilers evidently define NULL in a way that incorrect use of NULL as a pointer parameter will still function, but it is still INCORRECT and UNPORTABLE! Please do NOT encourage people to program in this incorrect manner! 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.