Confused by syntax

how is:

wr=(wr=wtemp)*wpr-wi*wpi+wr;

different from this:

1
2
wtemp=wr;
wr=(wtemp)*wpr-wi*wpi+wr;


any comment?
In the first case you're reading from wr and writing to wr without synchronization. If wr is a scalar (for
example, a double or an int), the program has undefined behavior, anything can happen. If it's a class object, there are two equally correct possible outcomes.

Your second code sample is well-defined and thus can be reasoned about.

If you're not familiar with expression evaluation rules, check out http://en.cppreference.com/w/cpp/language/eval_order
Last edited on
sorry...should have read:

wr=(wtemp=wr)*wpr-wi*wpi+wr

how is that different than the 2 lines from above?
Last edited on
Those are the same for built-in operators (assuming temp is supposed to be wtemp). What caused the doubt?
I thought they were...not familiar with C++ so i wasn't sure if this did a different order of ops...

thanks for the feedback.
Topic archived. No new replies allowed.