How to fill the type int C+++



  • I need to catch int refilling without using math.
    But the practice has shown that it is unrealistic to make a mistake about overcrowding. Once the type is overcrowded, the programme does not throw an exception or a mistake to be processed.
    How do you recommend a comparison: if the meaning of the erroneous communication is no longer appropriate.



  • Type conversion int http://eel.is/c++draft/expr#4 (UB) and it can't be in C+++.

    In practice, the C+++ compiler may remove the code of the checking refilling intbecause there's no overcrowding.

    If overfilling int There will be no further conduct of the programme, and any post-screening is pointless, as the programme is already in an unfit condition.

    The possibility of overcrowding can only be verified prior to the operation, which may cause it, for example:

    int x;
    if (x != INT_MAX) {
      ++x;
    } else {
      // будет переполнение
    }
    

    Note:
    On platform x86 there's an instruction intobut it's not available from C+++.


    There's an op in the gcc compilator. -fstrict-overflowwhich deactivates the optimization associated with the impossibility of overcrowding characters. This allows for the compiling of an old code that violates the overfilling ban. int♪ In the new code, however, this option should not be used and a code conforming to the requirements of the standard should be written.



Suggested Topics

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