title: Casting int to bool in C/C++
body: <p>I know that in C and C++, when casting bools to ints, <code>(int)true == 1</code> and <code>(int)false == 0</code>. I'm wondering about casting in the reverse direction...</p>
  
  <p>In the code below, all of the following assertions held true for me in .c files compiled with Visual Studio 2013 and Keil µVision 5. Notice <code>(bool)2 == true</code>.</p>
  
  <p>What do the C and C++ standards say about casting non-zero, non-one integers to bools? Is this behavior specified? Please include citations.</p>
  
  <pre><code>#include &lt;stdbool.h&gt;
  #include &lt;assert.h&gt;
  
  void TestBoolCast(void)
  {
      int i0 = 0, i1 = 1, i2 = 2;
  
      assert((bool)i0 == false);
      assert((bool)i1 == true);
      assert((bool)i2 == true);
  
      assert(!!i0 == false);
      assert(!!i1 == true);
      assert(!!i2 == true);
  }
  </code></pre>
  
  <p><strong>Not</strong> a duplicate of <a href="https://stackoverflow.com/questions/2725044">Can I assume (bool)true == (int)1 for any C++ compiler?</a>:</p>
  
  <ol>
  <li>Casting in the reverse direction (int --> bool).</li>
  <li>No discussion there of non-zero, non-one values.</li>
  </ol>