Paul Schlie wrote on 08/06/2005 17:53:04:
>
> - I would have if someone could provide a concrete example of an
undefined
> behavior which produces a reliably useful/predictable result.
>
Well this is a simple hackery quiz, which is irrelevant to GCC.
1: int a, b;
2: int f() { return b++; }
3: int main(int argc)
4: {
5: b= argc;
6: a= b + f(); /* a==b*2 or a==b*2+1 */
7: a= a/2; /* a=b */
8: return a;
9: }
If one would claim that a is totally unconstrained at line 6, then this
example will be invalid. In that case, I can give a more restricted
example, where 'a' is computed speculatively and is discarded
in exactly the same cases when it is undefined.
Oh, well here it is.
1: int a, b, c;
2: int f() { return a ? b++ : b; }
3: int main()
4: {
5: scanf("%d %d", &a, &b);
6: c= b + f(); /* C is undefined if a != 0*/
7: if (a) c = b;
8: return c;
9: }
This example is predictable. I argue that it may be also
useful performance-wise to do speculative computations.
- Re: Ada front-end depends on signed overflow Paul Schlie
- RE: Ada front-end depends on signed overflow Dave Korn
- Re: Ada front-end depends on signed overflow Robert Dewar
- Re: Ada front-end depends on signed overflow Robert Dewar
- Re: Ada front-end depends on signed overflow Robert Dewar
- Re: Ada front-end depends on signed overflow Gabriel Dos Reis
- Re: Ada front-end depends on signed overflow Paul Schlie
- RE: Ada front-end depends on signed overflow Dave Korn
- Re: Ada front-end depends on signed overflow Michael Veksler
- Re: Ada front-end depends on signed over... Paul Schlie
- Re: Ada front-end depends on signed... Michael Veksler
- Re: Ada front-end depends on signed overflow Joe Buck
- Re: Ada front-end depends on signed over... Paul Schlie
- Re: Ada front-end depends on signed overflow Lassi A . Tuura
- Re: Ada front-end depends on signed overflow Bernd Schmidt
- Re: Ada front-end depends on signed overflow Paul Schlie
- Re: Ada front-end depends on signed overflow Georg Bauhaus
- Re: Ada front-end depends on signed over... Paul Schlie
