help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

detecting arithmetic overflows - Compiler specific flags


From: Karthik Kumar
Subject: detecting arithmetic overflows - Compiler specific flags
Date: Sat, 14 Aug 2004 03:07:25 -0700
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

Hi,
I have already posted the question to the gnu gcc n.g , but then found this n.g. and thought this question would be more appropriate here. My apologies in case you find this one repeated.

   I am writing this application that needs a lot of arithmetic
calculations. I was wondering if the GNU C++ compiler specifies any way of detecting arithmetic overflows. ( some extensions or flags or some options).

I was looking at overflow_error class provided by stdexcept library in C++. That does not seem to be raised automatically.

#include <iostream>
#include <stdexcept>
using namespace std;

int main() {
    try {
       short a = -10000;
       short b = a * 8;
    } catch ( overflow_error & r ) {
       // Oop !! No, arithmetic exception is not caught here.
    }
}

How would I handle similar situations ?

- Karthik.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]