Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!uwvax!oddjob!gargoyle!mason From: mason@gargoyle.UChicago.EDU (Tony Mason) Newsgroups: comp.lang.c Subject: Re: NULL pointers as arguments Message-ID: <641@gargoyle.UChicago.EDU> Date: Thu, 30-Apr-87 10:21:09 EDT Article-I.D.: gargoyle.641 Posted: Thu Apr 30 10:21:09 1987 Date-Received: Sat, 2-May-87 09:03:46 EDT References: <1130@ius2.cs.cmu.edu> <148@nbisos.NBI.COM> Reply-To: mason@gargoyle.uchicago.edu.UUCP (Tony Mason) Distribution: na Organization: U. of Chicago, Computer Science Dept. Lines: 45 >All of these problems would go away if people would cast NULL to the >proper value. > >"What about existing code which assumes .... ?" > >Tough ! It's wrong ! > >We don't need to change the language definition to support junior programmers. >If you can't use a simple tool like lint, then step aside and let someone >who really cares do the task. I'm so sick of all of the exceptions being >made to support and promote mediocrity ! It is NOT wrong. K & R EXPLICITY state that NULL IS the correct manner in which to represent this stuff. (K & R p. 97-98): "We write NULL instead of zero, however, to indicate more clearly that this is a special value for a pointer. In general, integers cannot meaningfully be assigned to pointers; zero is a special case." ^^^^^^^^^^^^^^^^^^^^^^ It would be rather difficult to defend the position that code using THIS assumption was written by "junior programmers" and that to conform to K & R is to "support and promote mediocrity." What we are arguing about are not problems with using the special symbol '0' but rather scoping rules in C. With the new ANSI standards, function prototyping should get rid of the problem. Point is, we have to live with what C is now and has been in the past. It doesn't suffice to say "it's wrong." K & R in the famous Appendix A sum it up (p. 192): "...it is guaranteed that assignment of the constant 0 to a pointer will produce a null pointer distinguishable from a pointer to any object." To say code using this fact is "wrong" isn't correct, OR productive. Useful suggestions (such as common coersion) may be acceptable FOR THE NULL POINTER case. From K & R, you could assume there was a pointer type "NULL" which was distinguishable from other pointer types. Thus, a NULL char * could be the same as a NULL struct x *. Coersion of NULL pointers only may be difficult, but it would conform, and solve the problem. Tony Mason Univ. of Chicago, Dept. of C.S. ARPA: mason@gargoyle.uchicago.edu UUCP: ...ihnp4!gargoyle!mason