On Tue, Jun 28, 2005 at 11:19:18PM +0200, Gabriel Dos Reis wrote: > Robert Dewar <[EMAIL PROTECTED]> writes: > > | Gabriel Dos Reis wrote: > | > Robert Dewar <[EMAIL PROTECTED]> writes: > | > | "has the semantics that Gabriel Dos Reis wants" is not an evaluable > | > | predicate! > | > You completely missed the point, but I guess it is consistent with > | > your denying that there is any connection between C or C++ and > | > hardware. > | > | So, let's make this MUCH more specific. Gabriel, on the MIPS chip, > | do you think there is something in the definition of C that leads > | you to prefer wrap around semantics to trapping semantics? > > When it comes down for the compiler writer to chose something for > undefined behaviour, it is hardly solely based on the C standard. > In fact, the C standard is of much less help because it gaves up. > So, your question is inconsistency in terms.
I think it would make sense to use a *mix* of trapping and non-trapping instructions myself; it would *not* make sense to use trapping everywhere. For one thing, wrapping arithmetic is associative; trapping arithmetic is not. (a+b)+c is not the same as a+(b+c) if we trap, because the former might not overflow while the latter does. Forcing the compiler to keep track limits the optimization possibilities. However, for address generation the value of catching bounds errors outweighs these penalties. So I guess I agree with Gaby in that there are a number of practical considerations that come into play. Conformance with the standard requires that valid programs do the right thing, but it is an engineering compromise what to do when undefined behavior is invoked. Writers of code often accidentally rely on wrapping without realizing it; it can cause sums of three integers to come out correct despite an overflow of the intermediate term. We can argue that they shouldn't rely on such things, but the usual software development methodology, like it or not, is to hack away quickly, then start testing and fixing bugs, so overflows that don't affect the result will simply not be noticed.