News for hackers. Stuff that matters.
Re:Catching Integer Overflows in C by praptak on Tuesday August 02, 2011 @09:01AM (#2836942)
This (I mean lack of overflow checking in arithmetic) is one of the areas where C shows its weakness as a sort of a lowest common denominator assembly. If at all possible (portability be damned) I'd prefer to crank out the inline __asm__ and get the access to the overflow flags of the underlying CPU.
Re:Catching Integer Overflows in C by tptacek on Tuesday August 02, 2011 @09:26AM (#2837004)
How much does that _really_ help you? The C code to detect an overflow given the context (adding, multiplying, subtracting, &c) isn't difficult. The reason integer overflows are pernicious is that they're easy to miss.
Re:Catching Integer Overflows in C by praptak on Tuesday August 02, 2011 @09:55AM (#2837101)
Valid point. But it's not about the difficulty - the macros are probably easier. I just simply don't like the pattern of the compiler discarding the information and the macros (indirectly) reconstructing it.

If you need the information then the straightforward thing to do is not to discard it in the first place.

Re:Catching Integer Overflows in C by 1amzave on Tuesday August 02, 2011 @10:51PM (#2839637)
I'm kind of surprised GCC doesn't have a __builtin_* extension for overflow detection. It seems like a pretty natural fit among a lot of the other ones.

...and after a quick bit of googling, it appears this has been discussed by the GCC devs semi-recently: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48580