Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Both ISO C and ISO C++ standards guarantee that unsigned arithmetic is modulo 2<sup>n</sup> - i.e., for any overflow or underflow, it "wraps around". For ISO C++, this is 3.9.1[basic.fundamental]/4:</p> <blockquote> <p>Unsigned integers, declared <code>unsigned</code>, shall obey the laws of arithmetic modulo 2<sup>n</sup> where <em>n</em> is the number of bits in the value representation of that particular size of integer.<sup>41</sup></p> <p>...</p> <p>41) This implies that unsigned arithmetic does not overflow because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting unsigned integer type.</p> </blockquote> <p>For ISO C(99), it is 6.2.5/9:</p> <blockquote> <p>A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.</p> </blockquote> <p>Which means the result is guaranteed to be the same as <code>SIZE_MAX - (sizeof(struct foo)) + 1</code>.</p> <hr> <p>In ISO 14882:2003 5.3.1.7:</p> <blockquote> <p>[...] The negative of an unsigned quantity is computed by subtracting its value from 2<sup>n</sup>, where <em>n</em> is the number of bits in the pro- moted operand. The type of the result is the type of the promoted operand.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload