I was working on a programming problem, is there a way to check for overflow errors for a signed 32-bit integer without the use INT_MIN and INT_MAX macros of climits.
            Asked
            
        
        
            Active
            
        
            Viewed 46 times
        
    1 Answers
2
            
            
        It's impossible to check for overflow errors using any technique. That's because the behaviour of signed int overflow is undefined in C++.
What you can do is write pre-emptive code that detects a potential overflow. The nature of that code is contingent on the operations you are performing. But it would be rather difficult to do that without using std::numeric_limits<int> functionality (which supersedes INT_MIN and INT_MAX) if you want to write portable C++.
 
    
    
        Bathsheba
        
- 231,907
- 34
- 361
- 483
