icky C code
Gregory Smith
greg at utcsri.UUCP
Fri Jul 18 05:00:11 AEST 1986
In article <2446 at umcp-cs.UUCP> chris at 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
More information about the Comp.lang.c
mailing list