Overcrowding control



  • The cycle takes action on the variable type int♪ At some point, the value may exceed the maximum permissible value. How do you control that?



  • ♪ https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html and http://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins There are built-in functions for arithmetic operations with overflow control.

    For example, x += y You can write.

    int tmp;
    if (__builtin_add_overflow(x, y, &tmp)) {
        ... переполнение ...;
    } else {
        x = tmp;
    }
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2