Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ecr.UUCP Path: utzoo!hcrvax!ecrhub!ecr!quenton From: quenton@ecr.UUCP (Dennis Smith) Newsgroups: net.lang.c Subject: Re: SIZEOF Message-ID: <351@ecr.UUCP> Date: Wed, 23-Jan-85 04:34:21 EST Article-I.D.: ecr.351 Posted: Wed Jan 23 04:34:21 1985 Date-Received: Fri, 25-Jan-85 03:09:21 EST References: <347@ecr.UUCP> Organization: Emerald City Research, Toronto Lines: 27 The problem of passing 0 for a null pointer (as a parameter), and the solution of "#define NULL ...", as pointed out by P.Curran, is valid. However, the use of - #define NULL ((char *)0) although portable will cause many compilers to complain about differing pointer types, and will also cause lint to generate many additional useless messages. The only generally useable solution that I know of is - #define NULL 0 /** when sizeof(xxx *) == sizeof(int) **/ #define NULL 0L /** when sizeof(xxx *) == sizeof(long) **/ This unfortunately means that the "define" must be changed whenever the target machine/compiler/environment changes. One possible solution for the future could be the use of - #define NULL ((void *)0) which seems compatable with the notation of (void *) being a generic pointer type. It might also be noted, although I have had no experience with them, some compilers for certain older generations of computers, generate pointers of differing sizes. This occurs when the machine is not byte addressable, so that a pointer to a word aligned item might be "n" bits long, but a pointer to a character must point to the word and also indicate which character within the word. This would make the even more disastrous situation of sizeof(char *) != sizeof(int *) making the defintion of something like NULL even more incomprehensible.