icky C code

Gregory Smith greg at utcsri.UUCP
Mon Aug 4 13:28:28 AEST 1986


In article <19880 at rochester.ARPA> crowl at rochtest.UUCP (Lawrence Crowl) writes:
>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 ).
>
>Since there is no type checking between an external definition of a function

	There is lint, which does this.

>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.
>
>So, the optimization would probably break some programs.

Very likely, but only incorrect ones. This 'implicit casting' is not
legal C. It is much the same as passing an int to a function which
expects a struct containing a single int - it will usually work, but if
(when) it doesn't, the programmer is at fault. Would you call that
'implicit casting'?

 I assert that a 68K C implementation could be made which returns
pointers in A0 and ints in D0, and no lintable program would be broken.
(If this is not the case, then lint needs work :-) )


-- 
"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



More information about the Comp.lang.c mailing list