Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a number of fine points here:</p> <ul> <li>The Compiler does not even have to look at the initialization of k to prove that the condition k==-1 can never be true in the unsigned char case. The point is, that the <strong>unsigned</strong> 8 bit value needs to be promoted to 32 bits, because the right hand side of the comparison is an integer constant, which is by default 32 bits. Because k is unsigned, the result of this promotion will be <code>00000000 00000000 00000000 xxxxxxxx</code>. The constant -1 has the bit pattern <code>11111111 11111111 11111111 11111111</code>, so it does not matter what <code>xxxxxxxx</code> is, the result of the comparison will always be false.</li> <li>I might be wrong on this point, but I believe that even if k was specified as volatile, the compiler would only be required to load it into a register (because the load operation might trigger some desired side effect in the hardware), not to actually perform the comparison or produce code for the unreachable if-block.</li> <li>Actually, omiting producing assembly for unreachable code is entirely in accordance with the goal of -O0 to speed up the compilation process.</li> <li>AFAIK, the comparison between an unsigned and a negative constant is undefined behaviour anyway. At the very least, there is simply no machine instruction to correctly handle the case, and compilers won't insert the necessary code to handle it in software as you can see from the disassembly. All you get is an implicit cast between signed and unsigned that results in an integer overflow (which is undefined behaviour in itself), and a comparison of unmixed sign.</li> </ul>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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