Re: Same code and different result, Why?



"Tommy" wrote:
Just consider from a functional programming standpoint, where
IMV, many programmers trained as engineers do alot.

inline int INC(int &i) { return i++; }
// note: don't focus on the inline, just an illustration
..

int x = 36, y = 20;
x = INC(x) + INC(y);

the result is correctly different. Sure, who would do this when
the language itself offers this functionality.

But the whole point is that the language offers two distinct ways
to increment:

inline int POST_INC(int &i) { int tmp = i; i += 1; return tmp; }
inline int PRE_INC(int &i) { i += 1; return i; }

In the C++0x standard the usage of PRE_INC yields well-defined
result, as Igor already noticed. It is only POST_INC implies
undefined behavior.

In all the cases, in each one, whether its code reduction,
functional programming, Algebraic or RPN calculations, APL or
the like oriented languages, the results are ALL the same, but
different than:

x = x++ + y++;

and best from what I tell, its a MS Compiler issue only -
excused with the documented sequence point idea.

No, it is undefined for all other compilers, as well. The notion
of sequence point is common for all C/C++ compilers. However, the
exact place where sequence point occurs may vary from vendor to
vendor.

I think that B. Stroustrup answerd to you claim better than I
could:

"Why are some things left undefined in C++?"
http://www.research.att.com/~bs/bs_faq2.html#undefined

Alex


.



Relevant Pages

  • Re: The annotated annotated annotated C standard part 3
    ... we have people raving here that "sequence points ... took this to a new stage beyond existing language documents. ... multiple execution streams. ... C was correct in not trying to force compilers to detect multiple writes ...
    (comp.programming)
  • Re: Why the VB6 versus VB.NET contest is baloney
    ... You then have a core language with possible vendor-specific and/or OS-specific extensions, but you're not tied into a single vendor with no real recourse. ... Fortran has had it since at least '66, C since '89, I don't know of the earliest C++ or PL/I or Ada or Standard dates, but they all have multiple compiler vendors. ... Some of them even have MS compilers:) Many even have open source compilers as well. ...
    (microsoft.public.vb.general.discussion)
  • Re: Why the VB6 versus VB.NET contest is baloney
    ... has compilers from more than one vendor. ... You then have a core language ... not tied into a single vendor with no real recourse. ...
    (microsoft.public.vb.general.discussion)
  • Re: Why the VB6 versus VB.NET contest is baloney
    ... imo it should be a language that has a recognized Standard and has compilers from more than one vendor. ... You then have a core language with possible vendor-specific and/or OS-specific extensions, but you're not tied into a single vendor with no real recourse. ...
    (microsoft.public.vb.general.discussion)
  • Re: Why the VB6 versus VB.NET contest is baloney
    ... has compilers from more than one vendor. ... You then have a core language ... not tied into a single vendor with no real recourse. ...
    (microsoft.public.vb.general.discussion)