|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Keith Thompson wrote:
<snip> > Of course signed integer overflow isn't required to > result in wraparound. The compiler *could* set ``whats_this'' to 0, > or to a value derived from the current phase of the moon. <snip> <OT> I am afraid (really and truly) that the statement isn't incorrect. I mean, we expect the compilation of the same translation unit with the same command line of the compiler invocation to be repeatable. [It wasn't on a version of my compiler and was acknowledged as a bug.] Is there any wording somewhere to that end? [I am afraid, no, or some linkers won't have a habit of planting a timestamp in the executable.] </OT> -- Ark |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Ark Khasin <akhasin@macroexpressions.com> writes:
> Keith Thompson wrote: > <snip> >> Of course signed integer overflow isn't required to >> result in wraparound. The compiler *could* set ``whats_this'' to 0, >> or to a value derived from the current phase of the moon. > <snip> > > <OT> > I am afraid (really and truly) that the statement isn't incorrect. > I mean, we expect the compilation of the same translation unit with > the same command line of the compiler invocation to be repeatable. [It > wasn't on a version of my compiler and was acknowledged as a bug.] > Is there any wording somewhere to that end? > [I am afraid, no, or some linkers won't have a habit of planting a > timestamp in the executable.] > </OT> In practice, most such behavior is likely to be repeatable. For example, signed integer overflow *usually* wraps around, so INT_MAX+1 yields INT_MIN. But the standard merely says that the behavior is undefined. If your compiler has INT_MAX+1 yielding a value derived from the current phase of the moon, you might want to complain to your vendor, but you can't base your complaint on a violation of the standard, because there isn't one. If you think of the standard as a contract between the implementation and your program, it's your program that violated the contract by attempting to compute INT_MAX+1 (or whatever). More realistically, an optimizing compiler is allowed to *assume* that anything invoking undefined behavior will never occur. This can lead to surprising results. Unless, of course, your vendor chooses to *document* the behavior of signed integer overflow, effectively creating an addendum to the contract. -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst> "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
|
![]() |
| Outils de la discussion | |
|
|