> From: Michael Veksler <[EMAIL PROTECTED]> > Paul Schlie wrote on 20/06/2005 08:55:20: >> y = z ? z + x; // y == [INT_MIN+1, INT_MAX+2] > Invalid syntax, what did you mean?
Sorry, meant: y = z + x; // y == [INT_MIN, INT_MAX] + [1, 2] == [INT_MIN+1, INT_MAX+2] >> I guess I simply believe that optimizations should never alter the >> logical behavior of a specified program relative to it's un-optimized >> form unless explicitly granted permission to do so, therefore such >> optimizations should never be considered enabled at any level of >> optimization by default. > > As a user I sympathize with this wish. As someone who spent a whole > day wading through assembly to analyze a bug (undefined > behavior), I can tell you that I don't like it either. > > Yet, as a developer of another system with strict semantics I can > say that, in general, your requirements are impossible to follow, > unless very carefully worded. > > This requirement for "never alter the logical behavior" implicitly > forbids all optimizations in a language like C. > For example consider: > > 1: void foo() > 2: { > 3: int a; > 4: printf("%d\n", a); /* undefined behavior */ > 5: } > 6: void bar() > 7: { > 8: do something; > 9: } > 10:int main() > 11:{ > 12: bar(); > 13: foo(); > 14: return 0; > 15:} > > Almost any optimization over line 8 will change the > behavior of line 4. I believe that you did not intend to > cover this case in your requirement. Maybe you would > like to narrow the requirement such that it enumerates > all the cases you consider to "alter the logical behavior". > And even if you do, you'll have to be very careful to > define a consistent semantics for each case. Understood, but tried to be careful with my wording, as I didn't say alter the resulting value, but rather alter the logical behavior (i.e. semantics). As in my mind, the semantics of foo() dictate that it print the value of the storage location which was allocated to the variable "a", where unless "a" is initialized with an explicit value, may be arbitrary. So I've got no problem with arbitrary results or behavior, I just simply believe they are implicitly constrained to the remaining rules of the language, i.e. all side-effects must be expressed upon reaching a sequence point which logically bounds the effects of the evaluation of any expression. (where if an undefined behavior it did delete the program being executed it wouldn't resume execution beyond the next sequence point, but if it does, it must continue to abide by the languages rules regardless of the resulting side effects from the preceding behaviors)