Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!cmcl2!brl-adm!adm!dsill@nswc-oas.arpa
From: dsill@nswc-oas.arpa (Dave Sill)
Newsgroups: comp.lang.c
Subject: Re: Optimization (was Re: volatile)
Message-ID: <14340@brl-adm.ARPA>
Date: 12 May 88 16:59:19 GMT
Sender: news@brl-adm.ARPA
Lines: 46

Chip Salzenberg  writes:
>In article <13074@brl-adm.ARPA> dsill@NSWC-OAS.arpa (Dave Sill) writes:
>>This bears repeating.  There should be no circumstances under which
>>the semantics of the language are changed by a flag to the compiler.
>
>This statement is, in my opinion, usually true.  However, the semantics of
>C are not as simple as Dave Sill seems to think they are.  For example,
>Dave may consider:
>
>	a = b;
>	a = b;
>
>to mean "move data from b to a twice", which is what a simple C compiler
>might do.  On the other hand, some people -- myself included -- consider
>that same C fragment to mean "assign b's value to a, then assign b's value
>to a", which is redundant and subject to optimization.

I believe the semantics of C are not as complex as Chip Salzenberg
seems to think they are.  I don't remember anything in K&R that says
assignment means "assign b's value to a unless a probably already has
b's value, as far as the compiler can tell."

>Many people who complain about optimizers ass_u_me that they know what the
>output of the compiler should look like.  They are not really writing C,
>they are writing for an assembler pre-processor which happens to accept C
>syntax.  This method of programming is a Bad Thing, because it produces
>non-portable code.

There may be people like that, but I'm not one of them.  I don't mind
optimization AS LONG AS THE CODE WORKS THE WAY IT'S SUPPOSED TO.  In
the case of redundant assignments and such, I think a warning,
preferably from lint, is a better approach than assuming the
programmer made a mistake.

>Aggressive optimizers, on the other hand, are a Good Thing.  They allow
>programmers to write code which is fast _and_ portable.  Putting up with
>"volatile" and other optimizer controls is a small price to pay.

Sometimes any price is too high.

=========
The opinions expressed above are mine.

"We must remove the TV-induced stupor that lies like a fog across the
 land."
					-- Ted Nelson