Topic: C++ Evaluation Order


Author: Hyman Rosen <hyrosen@mail.com>
Date: Fri, 16 Apr 2010 12:33:06 CST
Raw View
On 4/15/2010 7:04 PM, armen.tsirunyan wrote:

> In C++ the order of evaluation of subexpressions in an expression(or
> the order of evaluatino of function arguments) is in general not
> specifed. What is the reason? I mean, what would be the cost of
> specifying that order, if any? Thank you.
>

It is believed by some that allowing the compiler to
pick the order in which it does operations can lead to
code which is so much more efficient that it is worth
leaving the order unspecified in the presence of side
effects (the compiler may already reorder expressions
without observable side effects due to the as-if rule).

I do not believe this myself, but there are enough who
do to prevent the language standard from being changed
in this regard.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "armen.tsirunyan" <lordn3mrod@gmail.com>
Date: Thu, 15 Apr 2010 17:04:12 CST
Raw View
In C++ the order of evaluation of subexpressions in an expression(or
the order of evaluatino of function arguments) is in general not
specifed. What is the reason? I mean, what would be the cost of
specifying that order, if any? Thank you.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: ThosRTanner <ttanner2@bloomberg.net>
Date: Fri, 16 Apr 2010 12:32:42 CST
Raw View
On Apr 16, 12:04 am, "armen.tsirunyan" <lordn3m...@gmail.com> wrote:
> In C++ the order of evaluation of subexpressions in an expression(or
> the order of evaluatino of function arguments) is in general not
> specifed. What is the reason? I mean, what would be the cost of
> specifying that order, if any? Thank you.

The reason (if this isn't in the FAQ) is that it was considered to
give compiler writers more flexibility for optimisations.

Depending on who you talk to the costs would vary from almost nothing
to compiler writers leaving the computer science scene in droves and
performance collapsing to the levels you used to get with Z80s.


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]