Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: SIZEOF Message-ID: <405@rlgvax.UUCP> Date: Tue, 29-Jan-85 20:22:20 EST Article-I.D.: rlgvax.405 Posted: Tue Jan 29 20:22:20 1985 Date-Received: Sun, 3-Feb-85 00:16:54 EST References: <347@ecr.UUCP> <351@ecr.UUCP> Organization: CCI Office Systems Group, Reston, VA Lines: 38 Xref: seismo net.lang.c:4186 > 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. As you state below, there are machines where sizeof(char *) != sizeof(int *). This solution (#define NULL ((char *)0)) is NOT valid on those machines. > 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 isn't a solution. There may be machines in which the bit pattern that (char *)0 represents is something other than N zeros, where N is the number of bits in an "int" or a "long int". > 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. This won't work either. If a routine expects an "int *", dammit, it expects an "int *", not an "int", not a "long int", not a "char *", and not a "void *". What is so d*mn difficult about putting in pointer casts? It's second nature to me now, and has been for several years - dating back to PDP-11 days when it wasn't a problem. Don't think of C as structured assembler, where you "know" what's "really happening". Use it as a typed language, albeit with weak type checking. Trust me, you'll be happier for doing so. Can we put this discussion to bed now, with the conclusion that the only correct solution to the problem, pending ANSI Standard C with the ability to import the declaration of the arguments to a routine, is to put the ****** pointer casts in? Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy