7 ms·
You seem to be asking for quite some magic in that __no_overflow idea. It might be possible with a trivial expression like this, but what if there are function
by CUViper 11y ago
You seem to be asking for quite some magic in that __no_overflow idea. It might be possible with a trivial expression like this, but what if there are function calls in that expression, or even library calls? There are lots of places overflow could happen, and the site of your __no_overflow may not have code-gen control over it at all.
As for __checked, gcc has some builtins like this:
https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins...
- captainmuon 11y agoWell, it wouldn't reach into functions. It would mainly just change the + and - operators within its scope to return a larger type. So instead of int32_t plus(int32_t left, int32_t right); the plus operator would be equivalent to int64_t plus(int32_t left, int32_t right); So basically int32_t a = 2000000000; int32_t b = 2000000000; int64_t c = __no_overflow(a+b); // now c is 4000000000; I don't claim the idea to be flawless or completely thought out, but I believe something like that could be one of the more useful C language extensions. Oh, and thanks for the link!