Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Re: icky C code Message-ID: <3117@utcsri.UUCP> Date: Thu, 17-Jul-86 15:00:11 EDT Article-I.D.: utcsri.3117 Posted: Thu Jul 17 15:00:11 1986 Date-Received: Thu, 17-Jul-86 15:16:56 EDT References: <2239@brl-smoke.ARPA> <2446@umcp-cs.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 34 Summary: Fun with registers In article <2446@umcp-cs.UUCP> chris@maryland.UUCP (Chris Torek) writes: >>There is code which relies on ints and pointers being the same size. > >Alas, this seems to creep in everywhere---usually as a result of >programmer laziness. An imagined programming session: > > /* Oops, gotta call getenv, but the declarations are all > way above. Enh, I won't bother declaring it. */ > p = (char *) getenv("FOO"); > >First, this is bad coding, like writing unnecessary LOOPHOLEs in Mesa. >Second, lint will complain. Third, it is not really all that hard to >go put in the declaration. Leave out the cast and even the compiler >will complain, which will remind you to go clean up! > Fourth, it is not guaranteed to be portable. It will probably be a lot more portable than it should be, though. Compiler implementors have gone to surprising lengths to allow this sort of thing. From a code efficiency standpoint, for example, a 68000 should return int's in D0 and all pointer types in A0, which would break the above. ( Somebody pointed out that a certain 68K compiler has an option to return both types in *both* regs ). Or am I wrong, and there is a non-unwritten ( i.e. official ) rule that says everything should return in the same reg whenever possible? Imagine a library function ( coded in assembler ) which returns a useful int value if declared int and a useful, different, pointer value if declared as a pointer! ( not a serious suggestion, but would be feasible if the same code were given two names ). -- "You'll need more than a Tylenol if you don't tell me where my father is!" - The Ice Pirates ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg