Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!lll-crg!lll-lcc!pyramid!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.lang.c Subject: Re: icky C code Message-ID: <5768@sun.uucp> Date: Sun, 3-Aug-86 16:50:41 EDT Article-I.D.: sun.5768 Posted: Sun Aug 3 16:50:41 1986 Date-Received: Mon, 4-Aug-86 06:27:26 EDT References: <2239@brl-smoke.ARPA> <2446@umcp-cs.UUCP> <3117@utcsri.UUCP> <688@mordred.purdue.UUCP> <19880@rochester.ARPA> Organization: Sun Microsystems, Inc. Lines: 24 > 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@sun.com (or guy@sun.arpa)