Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: Another silly question
Message-ID: <1989May21.205928.26064@utzoo.uucp>
Organization: U of Toronto Zoology
References: <17812@cup.portal.com> <607@kl-cs.UUCP> <749@mccc.UUCP> <1989May19.154248.426@utzoo.uucp> <755@mccc.UUCP>
Date: Sun, 21 May 89 20:59:28 GMT

In article <755@mccc.UUCP> pjh@mccc.UUCP (Pete Holsberg) writes:
>=>Can you explain why compilers produce different code for "a[i]" and "*(a+i)"?
>=
>=Incompetent compiler writers.
>
>ALL of them?  Really?  Can you name a C compiler that was written by a
>competent compiler writer?

Sometimes I think the only one was Dennis Ritchie's original pdp11 compiler,
with the original PCC perhaps a borderline case.  And lest there be any
doubts about the matter, both of them convert "a[i]" to "*(a+i)" as they
parse, so the code for the two expressions is necessarily identical.  (I
went and looked at the compiler sources to be sure.)

The two expressions are semantically identical by the definition of C.
Any compiler which generates different code for them either is broken or
has outsmarted itself in trying to be clever.

>(Your new .sig is D U L L!! ;-)

Just wait for the next one. |->             <--- evil smile
-- 
Van Allen, adj: pertaining to  |     Henry Spencer at U of Toronto Zoology
deadly hazards to spaceflight. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
