[Info-vax] decrementing & for loops in C
Tim E. Sneddon
tesneddon at bigpond.com
Fri Jan 9 13:03:07 EST 2009
Bill Gunshannon wrote:
> In article <RBJ9l.9487$cu.6865 at news-server.bigpond.net.au>,
> "Tim E. Sneddon" <tesneddon at bigpond.com> writes:
>> Bill Gunshannon wrote:
>>> In article <49667A6E.3050507 at nowhere.com>,
>>> nobody <nobody at nowhere.com> writes:
>>>> Turning off optimization should normally cause the program to execute
>>>> your program exactly as written.
>>> A program should always execute exactly as written. No machine is smart
>>> enough to second guess the intent of a human.
>>>
>> That is arguable. After your code has been optimised
>> it doesn't quite execute 'exactly as written'. The
>> end result might be 'exactly as written'. However, the
>> path to get there has been completely shuffled around
>> by the compiler.
>
> Well, let's be clear on this. By "exactly as written" I mean just what it
> says. Not "as the writer intended", but "exactly as written". That allows
> for optimizing out code that would never be executed because I wrote the
> code wrong, like the original example. It may not be what I wanted, but
> it is what I wrote. But, the system should not be changing the order of
> operations for any code I wrote because it has absolutely no way of
> determining that there was not a particular reason for doing it in that
> order. No machine (or compiler) is that smart. Someone mentioned Ada
> doing this in an earlier post. Knowing what the primary purposes of Ada
> are, that would really scare me.
> "Let's see. The programmer wants me to check for weight on the wheel
> struts before raising the landing gear. but I think it would be much
> more efficient to raise the gear first." :-)
>
> What, you say that's just silly. How about this?
>
No, that's not silly. It's funny, I smiled too :-) However, it's
comparing apples and oranges. Your example above is a lot higher
level than scheduling instructions for improved performance. The
comment was about optimisation, not writing a compiler that lands
planes in it's spare time.
> {
> int thrust_reversers, power_level;
>
> { thrust_reversers = 10; power_level = 20; }
> }
>
> Does the order of these two (apparently) equal operations make a difference?
> Can a machine determine that?
Of course it can. Compilers build dependency graphs to figure
this sort of thing out. Compilers don't care about names.
To a compiler you may as well have written:
{
int i, j;
{ i = 10; j = 20; }
}
Tim.
More information about the Info-vax
mailing list