Path: utzoo!mnetor!uunet!husc6!mit-eddie!killer!richardh From: richardh@killer.UUCP (Richard Hargrove) Newsgroups: comp.unix.questions Subject: What is NULL? (was "Re: regcmp()") Message-ID: <3458@killer.UUCP> Date: 22 Feb 88 19:10:11 GMT References: <9@vsi.UUCP> <15100006@bucc2> Sender: 0000-Admin(0000) Organization: The Unix(R) Connection, Dallas, Texas Lines: 30 Summary: casts convert! In article <15100006@bucc2>, brian@bucc2.UUCP writes: > > > Not if you cast it to "char *", it isn't! Passing "(char *)0" is quite > > sufficient, unless the compiler is horribly broken. > > Tsk, tsk, tsk. This statment is true if sizeof(int) == sizeof(pointer). > Not a good assumption to make, eh? I do a great deal of programming using > Microsoft C 5.0 on IBM PEE CEE's. In large model, pointers are four bytes > long. However, constant integer expessions are ints, and an int is only two > bytes long. > This issue raises its ugly head periodically on comp.lang.c and generally causes a lot of consternation until the resident gurus beat it back down. The well established principle is that casts convert! If pointers are four bytes long, the cast should convert the two byte 0 to a four byte representation of the invalid pointer. In C, the value 0 is guaranteed to be an invalid pointer, even if the compiler must convert it to some other form (e.g., 0L). Any compiler that does not do this is indeed broken. The definition of NULL as 0L by C compilers targeted to the 80x86 is a kludge attempting to protect ignorant C programmers who don't cast NULL (which, to the compiler is indistinguishable from 0) when it is an actual parameter. This discussion should move to comp.lang.c since it is now a C issue. richard hargrove ...!{ihnp4 | codas | cbosgd}!killer!richardh --------------------------------------------