Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!sri-spam!mordor!lll-tis!ptsfa!ihnp4!homxb!houxm!hropus!ka From: ka@hropus.UUCP (Kenneth Almquist) Newsgroups: comp.lang.c Subject: Re: re-using registers Message-ID: <1162@hropus.UUCP> Date: Tue, 21-Jul-87 00:17:16 EDT Article-I.D.: hropus.1162 Posted: Tue Jul 21 00:17:16 1987 Date-Received: Tue, 28-Jul-87 02:12:11 EDT References: <2803@phri.UUCP> Organization: Bell Labs, Holmdel, NJ Lines: 36 > Imagine the following (rather silly) [code]: > register char *rs; > register struct foo *rp; > > for (rs = s; *rs != NULL; rs++); > for (rp = p; rp->next != NULL; rp = rp->next); > return; > Are there any C compilers (or other languages, for that matter) > which are smart enough to realize that rs and rp could be put in the same > register? There are certainly a lot of compilers for languages other than C which are that smart, IBM's PL/1 Optimizing Compiler being just one example. > In Fortran you would write this as "EQUIVALENCE (RS, RP)" and > the compiler wouldn't have to be smart at all, but that's cheating. In C, you should write: { register char *rs; for (rs = s; *rs != NULL; rs++); } { register struct foo *rp; for (rp = p; rp->next != NULL; rp = rp->next); } The standard joke is that in the C world, you don't have optimizing compilers, you have optimizing programmers. By the way, the FORTRAN equivalence statement may very well scare the optimizer out of putting either RS or RP in registers. Kenneth Almquist