Path: utzoo!mnetor!uunet!husc6!think!ames!umd5!uvaarpa!mcnc!rti!xyzzy!throopw From: throopw@xyzzy.UUCP (Wayne A. Throop) Newsgroups: comp.lang.c Subject: Re: Why NULL is 0 Message-ID: <687@xyzzy.UUCP> Date: 13 Mar 88 19:55:19 GMT References: <10576@mimsy.UUCP> <124@polygen.UUCP> Organization: Data General, RTP NC. Lines: 41 > pablo@polygen.uucp (Pablo Halpern) >> by chris@mimsy.UUCP (Chris Torek) >> [... on some existing architectures, pointers "naturally" have many >> sizes or formats... ] > However, if I were writing a C compiler, I would choose a size for all > pointers equal to the size of the largest possible pointer. This would > allow code that passed uncasted NULL to work correctly, provided NULL > is a type as large as a pointer. This also assumes that the nil pointer has the same format for all pointer types, and that passing protocols are also the same. Which, granted, might all be legislated so by the compiler implementor. *BUT* on some architectures, this would impose unacceptable performance or space consumption tradeoffs. For example, all pointers might have to be made twice as large as they might be. Or access times to unpack peculiar pointer formats from the "standard" one mandated by the compiler might be prohibitive. For example, look at the 80x86 family of architectures. Making all pointers 32 bits long and mandating everybody using the "huge" memory model (or whatever that model is called nowdays) suffers unacceptable performance degradataion for programs that could fit into a 16-bit address space. > This is not because dpANS says it > should be so, but because so much code would break if it were not. > Perhaps ANSI should add the restriction that all pointer types must be > the same size in an effort to "codify common existing practice." Well.... I don't admit that it is, indeed, "common existing practice" to assume that pointers are all the same size and the same format, no more than it is "existing practice" that pointers will fit in ints. Granted, there is code that makes this assumption, but it is not so universal as you assume, since all of these pointer assumptions have, in fact, been false since nearly the very beginning of C. I think that dpANS makes the proper tradeoff, and insists that there be a prototype in scope, or that an explicit cast occur. -- How often have I said to you that when you have eliminated the impossible, whatever remains, however improbable, must be the truth. --- Sir Arthur Conan Doyle {The Sign of the Four} -- Wayne Throop !mcnc!rti!xyzzy!throopw