Re: Benefit of not defining the order of execution
- From: Stephen Sprunk <stephen@xxxxxxxxxx>
- Date: Wed, 18 Feb 2009 14:28:03 -0600
Keith Thompson wrote:
Nate Eldredge <nate@xxxxxxxxxx> writes:cri@xxxxxxxx (Richard Harter) writes:(Think regression tests on log files.)
Huh?
Consider a program containing something like this:
double result = this() * that() + the_other();
Assuming that the three functions don't interact in any nasty ways
(depending on the same global variables, for example), the order of
evaluation shouldn't matter; result will get the same value for any of
the 6 possible orders. But suppose the functions contain trace
statements that (perhaps optionally) log information to a file. Then
the contents of the log can vary depending on the evaluation order,
and a testing scheme that looks for possible regressions by detecting
changes in the contents of the log will have problems.
Since the order of evaluation and thus the order of the log statements (side effects that _do_ interact in a "nasty" way) is unspecified, your testing scheme is broken if it assumes that your log statements are only correct when in a certain order.
If you want them to appear in a particular order, make proper use of sequence points to enforce that order. If you tell the compiler that the order doesn't matter, which is what you're doing when you write code such as above, then you shouldn't be surprised when it takes advantage of that.
S
--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Isaac Jaffe
.
- Follow-Ups:
- Re: Benefit of not defining the order of execution
- From: Richard Harter
- Re: Benefit of not defining the order of execution
- References:
- Benefit of not defining the order of execution
- From: somenath
- Re: Benefit of not defining the order of execution
- From: Kaz Kylheku
- Re: Benefit of not defining the order of execution
- From: Tim Rentsch
- Re: Benefit of not defining the order of execution
- From: nick_keighley_nospam
- Re: Benefit of not defining the order of execution
- From: Keith Thompson
- Re: Benefit of not defining the order of execution
- From: Richard Harter
- Re: Benefit of not defining the order of execution
- From: Flash Gordon
- Re: Benefit of not defining the order of execution
- From: Richard Harter
- Re: Benefit of not defining the order of execution
- From: Nate Eldredge
- Re: Benefit of not defining the order of execution
- From: Keith Thompson
- Benefit of not defining the order of execution
- Prev by Date: Re: Logical operator not working in if condition
- Next by Date: Re: Benefit of not defining the order of execution
- Previous by thread: Re: Benefit of not defining the order of execution
- Next by thread: Re: Benefit of not defining the order of execution
- Index(es):
Relevant Pages
|