Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: undesired optimiztion (was C++ coding standards) Message-ID: <422@taumet.com> Date: 27 Aug 90 17:29:52 GMT References: <883@zinn.MV.COM> <280@paradim.UUCP> Organization: Taumetric Corporation, San Diego Lines: 26 jean@paradim.UUCP (Jean Pierre LeJacq) writes: |In article <883@zinn.MV.COM>, mjv@objects.mv.com (Michael J. Vilot) writes: |> ... |> The Timer object `t' is only active in the inner block. Of course, the |> object is apparently never used, so I may get into trouble with those |> building aggressively-optimizing compilers. ... |C++ uses the keyword volatile to provide a hint to the compiler |to avoid aggresive optimization involving an object. Since it is |only a hint, I'm not sure how portable a solution this would be. E&S section 3.5: "A named local object may not be destroyed before the end of its block nor may a local named object of a class with a constructor or a destructor with side effects be eliminated even if it appears to be unused." So a correct compiler, even an agressively-optimizing one, may not omit (or move) the constructor/destructor Mike Vilot mentions. As Jean Pierre mentions, "volatile" is not guaranteed to do what you want, as its semantics are explicitly implementation-dependent (section 7.1.6). -- Steve Clamage, TauMetric Corp, steve@taumet.com