Another silly question

Henry Spencer henry at utzoo.uucp
Mon May 22 06:59:28 AEST 1989


In article <755 at mccc.UUCP> pjh at 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 at zoo.toronto.edu



More information about the Comp.lang.c mailing list