Path: utzoo!mnetor!uunet!lll-winken!lll-tis!oodis01!uplherc!sp7040!obie!wsccs!terry From: terry@wsccs.UUCP (Every system needs one) Newsgroups: comp.lang.c Subject: Re: Optimization (was Re: volatile) Message-ID: <511@wsccs.UUCP> Date: 30 Apr 88 04:58:54 GMT References: <13074@brl-adm.ARPA> <3938@killer.UUCP> Lines: 63 Summary: urg. In article <3938@killer.UUCP>, chasm@killer.UUCP (Charles Marslett) writes: > In article <13074@brl-adm.ARPA>, dsill@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!' |