This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ada front-end depends on signed overflow







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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]