icky C code

Guy Harris guy at sun.uucp
Mon Aug 4 06:50:41 AEST 1986


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

Those programs are already broken; it's just by pure luck that they happend
to work on some C implementations.  They also won't work on any C
implementation where "sizeof(char *)" is different from "sizeof(int)";
nothing forbids such an implementation.  "lint" will catch illegal code like
the example above.

It would be nice if compilers started giving warnings for using undeclared
functions, and if the "a function can be implicitly declared as 'int' by
usage" rule were deprecated by the ANSI standard.  Lazily-written code that
doesn't declare functions would still compiler under those compilers, and
work as well as it did before (which may mean "work just fine" and may mean
"not work at all"), but at least the programmer would be told that they may
be doing something wrong.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list