Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.lang.c Subject: Re: Casting NULL? Message-ID: <5557@brl-smoke.ARPA> Date: Fri, 23-Jan-87 17:40:11 EST Article-I.D.: brl-smok.5557 Posted: Fri Jan 23 17:40:11 1987 Date-Received: Mon, 26-Jan-87 01:40:18 EST References: <3179@brl-adm.ARPA> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 28 In article <3179@brl-adm.ARPA> Peter Steele - Acadia writes: >test( (char *)NULL, (char *)NULL ); >this is required because pointers to different types of objects >may not be the same size. I can appreciate this but how common >is it really? It's quite common, and furthermore NULL is usually 0 (an integer), which is often of a different size than any pointer. (Guy Harris, among others, explains this once or twice a year in this newsgroup.) Using an X3J11-compliant C implementation, if a function prototype is in scope when the invocation occurs, the parameters will be automatically converted to the type defined in the prototype. (Some of us don't like this feature, by the way, feeling that it encourages sloppy programming practices.) The really best way to think while coding C is to treat all data as strictly-typed, maintain absolute consistency in use of types, and in the (rare) instances when a type conversion is required, show it explicitly by using an appropriate cast. When I adopted this mental discipline, the reliability of my C code improved significantly (not to mention its portability). I even take it a step farther and maintain a distinction between Boolean and integer data types (not enforced by the language), using only Boolean expressions in conditionals, for example. This is perhaps the simplest example of the very important general principle of "data abstraction", which should be explained in good Computer Science textbooks.