Optimization (was Re: volatile)

Every system needs one terry at wsccs.UUCP
Sat Apr 30 14:58:54 AEST 1988


In article <3938 at killer.UUCP>, chasm at killer.UUCP (Charles Marslett) writes:
> In article <13074 at brl-adm.ARPA>, dsill at NSWC-OAS.arpa (Dave Sill) writes:
> > Terry Lambert writes:
> > >Basically, if it works without -O, it should work with -O, regardless of what
> > >the compiler writer's optimization does to achieve its goal.  If this makes
> > >writing compilers harder, so what?
> > 
> > This bears repeating.  There should be no circumstances under which
> > the semantics of the language are changed by a flag to the compiler.
> 
> Actually, I have written code the broke with optimization turned on
> on every machine I've found with a Unix-derived C compiler (and at least
> two that are not Unix-derived).  Memory mapped I/O drivers almost always
> blow up when you have sequences like
> 
>       port->data = 0;
>       port->data = 0;
>       port->data = 0;
>       port->data = 2;

They also blow up 1) when they are written wrong, 2) the memory mapping is
changed without corresponding changes to the code, or 3) they are trying
to talk to a VME bus when running on you QBUS machine.

> So are we to say that no one has yet written a C compiler?

No.  We say your code is broke and/or non-portable.  Strictly speaking, if
non-portable is it, it is broke.  It's one of the reason's I've come around
to volitile for some few cases.  I'd support it a lot better if it were
possible to declare functions this way to avoid problems with shareable
library routine updates.

> At least for Unices?

This is laughable, considering where C came from.

> I may be picky, but if flags to the compiler should not change the semantics
> of the language (in the broadest sense of the definition of semantics) -- what
> good are they.

I *never* wait for errors!  If they want me, they know where to find me ;-)!

The reason is simple.  Say I want a source-level debugger and have the stupid
insight to turn off the optimizer so I have assembly code which corresponds
to source on a line-by-line basis.  This is one hell of an incentive to have
code behave the same way with or without -O!  How do I debug something if
my debugger is only useful when there isn't a problem?  GAAAK!  You mean I
was right when I said before that looking at assembly was still useful?!?
(Henry, eat your hat!;-)

> Why type the things in if they don't affect the generated
> program (unless they triger off a pretty listing or play music while we
> wait for errors, I guess ({:)  ).

I didn't say they shouldn't effect the generated program, I said that they
shouldn't effect the OPERATION of the generated program.


| Terry Lambert           UUCP: ...{ decvax, ihnp4 } ...utah-cs!century!terry |
| @ Century Software        OR: ...utah-cs!uplherc!sp7040!obie!wsccs!terry    |
| SLC, Utah                                                                   |
|                   These opinions are not my companies, but if you find them |
|                   useful, send a $20.00 donation to Brisbane Australia...   |
| 'Admit it!  You're just harrasing me because of the quote in my signature!' |



More information about the Comp.lang.c mailing list