icky C code

Lawrence Crowl crowl at rochester.ARPA
Sat Aug 2 13:03:05 AEST 1986


In article <3117 at utcsri.UUCP>, greg at utcsri.UUCP (Gregory Smith) writes:
> 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?

Since there is no type checking between an external definition of a function
and its actual definition, a programmer could implicitly type cast by listing
the external definition with a different return type than the actual.  If
integers are put in D0 and addresses in A0, then the calling function would
grab the return value from the wrong register.

extern int f() ;
                               BUT
usage( ) { int i = f() ; }             char *f() { return "ptr" ; }
/* grabs from D0 */                    /* puts in A0 */

So, the optimization would probably break some programs.
-- 
Lawrence Crowl			716-275-5766	University of Rochester
			crowl at rochester.arpa	Computer Science Department
 ...!{allegra,decvax,seismo}!rochester!crowl	Rochester, New York,  14627



More information about the Comp.lang.c mailing list