Re: Same code and different result, Why?
- From: Tommy <tommy767@xxxxxxxxx>
- Date: Thu, 06 Nov 2008 06:43:44 -0500
Alex Blekhman wrote:
"Lorry Astra" wrote:Is this realated with compilor or CPU achitechure? Why?
In addition to Ulrich's answer.
"[39.15] Why do some people think x = ++y + y++ is bad?"
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15
HTH
Alex
Whats more fascinating is that there compiler differences especially with equivalent CORPORATE languages like FORTRAN.
Personally, sequence point or not, I would view the MS compiler is wrong here for producing results that are illogical to the application developer, again, as noted else where for similar arguments, who are NOT the same pay level to do understand these subtle points. IMV, the OP code is not as obscure as some documented examples provided for sequence points gotchas with 'unrecommended' C construct.
In other words:
int x = 36; y = 20;
int t = x++ + y++;
x = t;
*SHOULD* yield the same results as:
int x = 36; y = 20;
x = x++ + y++;
which in the EYES of the programmer, is simply reusing storage for the final *expected* result by eliminating t - a form of "optimization" per se.
Note, I'm not arguing the reality, I just find it - well - NUTS! :-)
--
.
- Follow-Ups:
- Re: Same code and different result, Why?
- From: Paavo Helde
- Re: Same code and different result, Why?
- From: Liviu
- Re: Same code and different result, Why?
- From: Ulrich Eckhardt
- Re: Same code and different result, Why?
- From: Ben Voigt [C++ MVP]
- Re: Same code and different result, Why?
- From: Igor Tandetnik
- Re: Same code and different result, Why?
- From: Igor Tandetnik
- Re: Same code and different result, Why?
- References:
- Same code and different result, Why?
- From: Lorry Astra
- Re: Same code and different result, Why?
- From: Alex Blekhman
- Same code and different result, Why?
- Prev by Date: Re: using const & in function prototypes
- Next by Date: Re: problem with old name project files
- Previous by thread: Re: Same code and different result, Why?
- Next by thread: Re: Same code and different result, Why?
- Index(es):
Relevant Pages
|