|
|
Subscribe / Log in / New account

Better handling of integer wraparound in the kernel

Better handling of integer wraparound in the kernel

Posted Jan 26, 2024 19:32 UTC (Fri) by iabervon (subscriber, #722)
Parent article: Better handling of integer wraparound in the kernel

I wonder if it would be possible to get an operator into C that would take an expression without side effects and return true if it would overflow and false otherwise. Having it be an operator (like typeof) would mean that (from the point of view of C and the compiler) you're not evaluating the expression, so it's not UB, and the compiler would be able to optimize the case where, if the operator returns false, you do evaluate the expression, and also makes it easier to optimize overflow checks in general (since the optimal assembly doesn't actually do the inequality test the programmer wrote, but looks at the overflow flag after the addition).

The program would still have to duplicate the expression, but at least it would be easy to have a warning if they don't match.


to post comments

Better handling of integer wraparound in the kernel

Posted Jan 28, 2024 10:18 UTC (Sun) by khim (subscriber, #9252) [Link]

There's already a perfectly usable builtin that does exactly that.

Adding new operator would be useful only if it would be shown that built-in is not enough.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds