On 2 Jun 2007 at 16:06, dwight elvey wrote:
I'd expect the compile to do things in the needed
order. Fetch the
value of N to do something with( do the first increment ), calculate
the address ( in doing so apply the second increment) and store the
value into the array.
Having spent a few years with FORTRAN optimization, I can safely say
that all a compiler has to do is generate code that produces the
right result. Eliminating, variables, loops, expressions, reduction
in strength, moving instructions, inlining functions and a zillion
other tricks is how you win benchmarks and get contracts.
The thing that really plays hob with automatic optimization of C is
the d*mned pointers, which can pretty much refer to anything.
It's not really safe to assume that a compiler will generate what you
expect for anything other than trivial cases--and sometimes not even
then. But this isn't all bad--it frees the programmer to write code
that is easy to read and leaves the bit-twiddling to the compiler.
Or at least that's the theory.
Anyone remember the FORTRAN "ABNORMAL" declaration?
Cheers,
Chuck