Optimization (was Re: volatile)
Dave Sill
dsill at nswc-oas.arpa
Fri May 13 02:59:19 AEST 1988
Chip Salzenberg <chip at ateng.uucp> writes:
>In article <13074 at brl-adm.ARPA> dsill at 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
More information about the Comp.lang.c
mailing list