Re: Same code and different result, Why?



Tommy wrote:
Alex Blekhman wrote:

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, you missed the point. I'll try it this way.

In every technology, protocol, what have you, when they is a lack of
consensus, in principle, you use the best practice. This is part
for the course for the technology you are using right now, the
compiler, including the news groups protocol NNTP (RFC 977) you are
using, as well as, and especially in Email (RFC 5321) technology.

In all cases, it is not that behavior is not defined, it is
indeterministic, there could be many behaviors but generally well
defined set of behavior. So in principle, there is lack of
consensus for what is the correct behavior - which one is deemed
"more" correct.

This isn't a software only problem. What is "correct" behavior is
sometimes decided by the underlying hardware, and they are different.

On some hardware, the code sequence

y = *x++;

might be a single machine instruction, if x is stored in a register.
Now, the compiler writers for such a machine would be really upset if
they could not use that instruction, just because you sometimes want
to write

x = *x++;

instead. Making this well defined, might make everything else run
slower, on some hardware. Good or bad?


One concrete example of this is Java requireing IEEE floating point.
Regular and well defined. However, IBM mainframes do not have that, so
they require a $100k hardware extension to run Java properly.

http://www-03.ibm.com/systems/z/advantages/zaap/index.html


C++ doesn't specify its floating point format, and therefore works
without any extra hardware.


Bo Persson


.



Relevant Pages

  • Re: Fortran 2008 (was Re: Statement function host association)
    ... optimizing compiler for f77 code for their hardware. ... Other vendors were involved in this process too. ... compilers, but also there are numerous independent commercial ... 15 years or so of the new language features, array syntax still has ...
    (comp.lang.fortran)
  • Re: Warning: The structure contains misaligned fields
    ... end module test ... If you read he words it says WARNing. ... You have specified SEQUENCE ... Some compilers have options to hide the warning ...
    (comp.lang.fortran)
  • Re: Learning embedded coding, which uC?
    ... used Forth 10 or more years ago, modern Forth compilers ... terms of target memory usage. ... bottom-up debugging on the target hardware. ... Stephen Pelc, stephenXXX@xxxxxxxxxxxxxxxxxxxxxxxxxx ...
    (comp.arch.embedded)
  • Re: non-specific os C++ building
    ... C++ is a platform-independent language. ... the C runtime libraries. ... you will have to interface with the hardware ... ... There are C++ compilers ...
    (comp.lang.cpp)
  • 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)