Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For your question, the important part of the quote you've included is this:</p> <blockquote> <p>The negative of an unsigned quantity is computed by subtracting its value from 2ⁿ, where n is the number of bits in the promoted operand.</p> </blockquote> <p>So, to know what the value of <code>-0x80000000u</code> is, we need to know <code>n</code>, the number of bits in the type of <code>0x80000000u</code>. This is at least 32, but this is all we know (without further information about the sizes of types in your implementation). Given some values of <code>n</code>, we can calculate what the result will be:</p> <pre><code>n | -0x80000000u ----+-------------- 32 | 0x80000000 33 | 0x180000000 34 | 0x380000000 48 | 0xFFFF80000000 64 | 0xFFFFFFFF80000000 </code></pre> <p>(For example, an implementation where <code>unsigned int</code> is 16 bits and <code>unsigned long</code> is 64 bits would have an <code>n</code> of 64).</p> <hr> <p>C99 has equivalent wording hidden away in §6.2.5 Types p9:</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>The result of the unary <code>-</code> operator on an unsigned operand other than zero will always be caught by this rule.</p> <p>With a 32 bit <code>int</code>, the type of <code>0x80000000</code> will be <code>unsigned int</code>, regardless of the lack of a <code>u</code> suffix, so the result will still be the value <code>0x80000000</code> with type <code>unsigned int</code>.</p> <p>If instead you use the decimal constant <code>2147483648</code>, it will have type <code>long</code> and the calculation will be signed. The result will be the value <code>-2147483648</code> with type <code>long</code>.</p>
    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