From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,dab7d920e4340f12 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,dab7d920e4340f12 X-Google-Attributes: gid103376,public From: David Bonham Subject: Re: C is 'better' than Ada because... Date: 1996/08/02 Message-ID: <3201C1F3.7410@cpd.ntc.nokia.com>#1/1 X-Deja-AN: 171541211 references: content-type: text/plain; charset=us-ascii organization: Nokia Group mime-version: 1.0 newsgroups: comp.lang.c,comp.lang.ada x-mailer: Mozilla 3.0b5aGold (WinNT; I) Date: 1996-08-02T00:00:00+00:00 List-Id: Tim Behrendsen wrote: > if ((array[++n] = GetValue(arg)) != 0) { > .... > > v.s. a typical non-C language ... > > n = n + 1; > array[n] = GetValue(arg); > if (array[n] != 0) { > ... > } > > Now, which is easier to optimize? Well, let's try your example out on a "real world" compiler. I just asked VC++ to compile both fragments and the code generated is identical. I wasn't surprised by this - after all, the intermediate representations of these fragments are probably very similar even before the optimiser gets its hands on them and I guessed they'd be identical afterwards. With optimisation no longer an issue, we're down to factors like maintainability and I think you're right to rate these issues highly. > There just is no substitute for writing code with an eye toward what > the compiler can and will do with it. Absolutely. "A Retargetable C Compiler: Design and Implementation " by Fraser & Hanson is a real eye-opener when it comes to learning about the transformations the compiler will make to your source. -- David Bonham (bonham@cpd.ntc.nokia.com)