Article View: comp.lang.misc
Article #6726Re: Common subexpression optimization
From: Kristoffer Eriksson
Date: Thu, 15 Feb 1990 00:16
Date: Thu, 15 Feb 1990 00:16
25 lines
1754 bytes
1754 bytes
In article <14239@lambda.UUCP> jlg@lambda.UUCP (Jim Giles) writes:
>From article <2858@pkmab.se>, by ske@pkmab.se (Kristoffer Eriksson):
>> (And if you found the initial assignment to p (p = &a[0][0]) hard to
>
>I'll have to look at my example again, but I don't think I said just:
>"p = &a". What I thought I said was: "p = (int *) &a", which is
>correct.
Correct, yes, but you defeat any type-checking by the compiler, as the
cast overrides all checking. It hides the type of "a", both to the human
reader and to the compiler. If you accidentally substituted "a" for e.g.
a character string, the compiler would still accept and compile it.
Explicitly taking the address of the first element of the array exactly
states what you are doing, and automatically gives you the type of that
element. If it doesn't match the type of the variable it is being assigned
to, the compiler will tell you.
An alternative to the complicated expression "&a[0][0]" is the simple
"a[0]", but I think that one is more confusing to the reader, as it can
mean several different things.
--
Kristoffer Eriksson, Peridot Konsult AB, Hagagatan 6, S-703 40 Oerebro, Sweden
Phone: +46 19-13 03 60 ! e-mail: ske@pkmab.se
Fax: +46 19-11 51 03 ! or ...!{uunet,mcvax}!sunic.sunet.se!kullmar!pkmab!ske
Technical Details
Message-ID:
<2878@pkmab.se>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!luth!sunic!kullmar!pkmab!skeReferences:
<2858@pkmab.se> <14239@lambda.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!luth!sunic!kullmar!pkmab!ske From: ske@pkmab.se (Kristoffer Eriksson) Newsgroups: comp.lang.misc Subject: Re: Common subexpression optimization Message-ID: <2878@pkmab.se> Date: 15 Feb 90 00:16:47 GMT References: <2858@pkmab.se> <14239@lambda.UUCP> Organization: Peridot Konsult i Mellansverige AB, Oerebro, Sweden Lines: 25