Re: Same code and different result, Why?



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! :-)

--
.



Relevant Pages

  • Re: Same code and different result, Why?
    ... 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 ... which in the EYES of the programmer, is simply reusing storage for the ...
    (microsoft.public.vc.language)
  • Re: Write position
    ... But it's surprisingly hard to do in Fortran. ... the format correct to fill the record (including the newline sequence). ... NCOUNT = NCOUNT + 1 ...
    (comp.lang.fortran)
  • Re: Fuzzy matching of postal addresses [1/1]
    ... >position along the sequence. ... As to Python not being Fortran. ... Andrew McLean ...
    (comp.lang.python)
  • Re: Write position
    ... But it's surprisingly hard to do in Fortran. ... the format correct to fill the record (including the newline sequence). ... NCOUNT = NCOUNT + 1 ...
    (comp.lang.fortran)
  • Re: Is this legal and if not why not?
    ... > It seems to work but is it standard Fortran and if not why not? ... > end type TBase ... What OO function cannot be achieved with Fortran 90? ...
    (comp.lang.fortran)