Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!seismo!sundc!hadron!jsdy From: jsdy@hadron.UUCP Newsgroups: comp.lang.c Subject: Re: NULL pointers as arguments Message-ID: <563@hadron.UUCP> Date: Thu, 14-May-87 03:38:00 EDT Article-I.D.: hadron.563 Posted: Thu May 14 03:38:00 1987 Date-Received: Sat, 16-May-87 09:34:05 EDT References: <1130@ius2.cs.cmu.edu> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Distribution: na Organization: Hadron, Inc., Fairfax, VA Lines: 42 Summary: belated disagreement I haven't been able to trace down all the (branching) followups on this; but what I have seen implies that there is still a lot of disagreement. Let me see if I can elucidate, with some facts and concepts that have not (far as I can see) yet been brought together. In article <1130@ius2.cs.cmu.edu> edw@ius2.cs.cmu.edu (Eddie Wyatt) writes: > It seems to me that the problems of having foo(NULL) be correct on >whatever machine you are working on could be taken care of by >having pointer arguements aways be type coerced into whatever the >largest pointer type is on the machine (in cases presented to >me that is char *). This could be done as part of the language >definition just as the float parameter are typed coerced into >doubles. This assumes there is some bound on pointer type sizes >though. Any comments? Well, this is kind of what a (void *) declaration is for. An ob- ject of type (void *) can be coerced into any pointer type and back, which rather implies that its actual bit size is at least as large as any other pointer but does not mean that it actually is one of the other pointer types. Specifically, a ((void *) 0) can be co- erced into a NULL pointer of any type. This rather argues that there is a bound on pointer sizes, although I can think of some (not necessarily pathological) architectures for which this might not be the case. But! A NULL pointer does not necessarily have a 0 representation in every type, or even necessarily the same representation in any two types! If I declare foo(int *arg) in one module, but try to pass foo(void *) or foo(char *) in another, I may be totally scrod [fishy] if the data types have sufficiently different representa- tions and there is no function prototype in the second module to cause coercion (which, from the discussion, I assume is the case). One could coerce all pointer arguments to whatever the (void *) representation is; but that could be an expensive operation. And if NULL continues to be defined as 0 (which it will continue to do on some slow-to-change compilers for a while), we still have the problem of even determining that this is a pointer constant at all. Joe Yao jsdy@hadron.COM (not yet domainised) hadron!jsdy@{seismo.CSS.GOV,dtix.ARPA,decuac.DEC.COM} {arinc,att,avatar,cos,decuac,dtix,ecogong,kcwc}!hadron!jsdy {netex,netxcom,rlgvax,seismo,smsdpg,sundc}!hadron!jsdy