Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: Seven Original Sins of K&R (Long) Message-ID: <1990Oct5.165133.26651@zoo.toronto.edu> Organization: U of Toronto Zoology References: <12780@sdcc6.ucsd.edu> <1990Sep26.163927.26084@dg-rtp.dg.com> <1990Sep26.193626.721@phri.nyu.edu> <1990Sep27.073730.26575@warwick.ac.uk> <1990Sep27.131329.26616@phri.nyu.edu> <1990Sep28.144753.23727@zoo.toronto.edu> <3945@se-sd.SanDiego.NCR.CO <1283.270b3 <26661@shamash.cdc.com> Date: Fri, 5 Oct 90 16:51:33 GMT In article <26661@shamash.cdc.com> bls@u02.svl.cdc.com (Brian Scearce) writes: >This is the same as #define NULL '\0' >This is the same as #define NULL 0 > >Both are different from #define NULL (void *)0 > >Neither of the suggested #defines are guaranteed to work with >not-all-bits-0-for-NULL implementations if you pass NULL as a >parameter to a function with no prototype in scope. There is *no*, repeat *no*, definition of NULL that is guaranteed to work with not-all-bits-0-for-NULL implementations if you pass NULL as a parameter to a function with no prototype in scope. Actually, this is true even if null pointers are all-0-bits, because they may not all be the same size. Repeat after me, 512 times: The representation of different pointer types can be different. To turn NULL into a valid null pointer of a particular type, the compiler must know the exact type that is desired. In the absence of prototypes, the only way to give the compiler this information in function calls is to explicitly cast NULL to the desired type. No definition of NULL can ever remove the need for this, and lazy programmers are just going to have to learn to put the casts in. No legal program can tell the difference between #define NULL 0, #define NULL 0L, and #define NULL ((void *)0). (Even prototypes do not fully remove the need to be aware of this issue, since varargs functions still need the casts.) -- Imagine life with OS/360 the standard | Henry Spencer at U of Toronto Zoology operating system. Now think about X. | henry@zoo.toronto.edu utzoo!henry