The program:

/* Doc: does C implementation detect integer overflow?
*/
#include <stdio.h>

int main( void ) {
signed int I;
for ( I = 1; I *= 2; ) ;
printf( "Overflow undetected.\n" );
I = 42 / I;
}

... prints:

Overflow undetected.

Grrr.  I'd rather be informed of errors.  But I guess it's traditional to ignore
this one (I've tried a few other C implementations with similar results),
even though ANSI C allows reporting it:

        if an /exception/ occurs during the evaluation of an expression
    (that is, the result is not mathematically defined or not in the range
    of representable values for its type), the behavior is undefined.

From the CEEDUMP:

        PSW..... 078D2400 C7F089C0

I guess fixed-point overflow is disabled.  I see no option to enable it.
I could try turning it on in an assembler routine, but I suspect that
would break numerous run-time library routines.

Then:

CEE3209S The system detected a fixed-point divide exception (System Completion 
Code=0C9).
         From entry point main at compile unit offset +00000096 at entry offset 
+00000096 at address 47F089BE.
[1] + Done(136) ( gmake overflow 2>&1 | tee log ) &&amp; ./overflow
  50332526      Floating point exception        ./overflow

"Floating point"?  Oh, well.

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to