Optimization (was Re: volatile)

Chip Salzenberg chip at ateng.UUCP
Thu May 5 00:54:04 AEST 1988


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.

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.

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.
-- 
Chip Salzenberg                "chip at ateng.UU.NET" or "codas!ateng!chip"
A T Engineering                My employer may or may not agree with me.
  "I must create a system or be enslaved by another man's." -- Blake



More information about the Comp.lang.c mailing list