Re: Post Increment Operator ambiguity??
Bo Persson wrote:
" The reason for the undefined order of evaluation between sequence points
is, like ever so often in C++, efficiency. Compilers are given the liberty
to evaluate expressions in the order that is most efficient for a given
platform and processor."
I believe that is an important reason to do what C++ i doing, much more
important than the ability to write complex statements with multiple
updates.
I've heard that for 25 years (it is inherited from C). What I have never
seen is any study that showed that a given compiler could produce
significantly faster code for a real program if the order of evaluation
was undefined, rather than if it was defined.
I think it's a very reasonable thing to question. The downside of an
undefined order of evaluation is, it is not reliably possible to tell if
an expression has side effects or not. Therefore, one can have
thoroughly tested and working code suddenly mysteriously fail when
ported or when the compiler is updated or even when different switches
to the compiler are used.
In an era of ever increasing complexity of software, this can reasonably
be viewed as an unacceptable risk for an unproven benefit.
Java does have a defined order of evaluation. I've never heard anyone
comparing C++ efficiency with Java make any comment that Java was
weighed down by this constraint.
The D programming language currently follows the C++ rule of
implementation defined order of evaluation, but for 2.0 it's going to
get a defined order of evaluation. I don't think the C++ undefined rule
is going to fly for much longer.
----
Walter Bright
Digital Mars - C, C++, D programming language compilers
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]