title: C: gcc implicitly converts signed char to unsigned char and vice versa?
body: <p>I'm trying to learn C at got stuck with datatype-sizes at the moment.</p>
  
  <p>Have a look at this code snippet:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;limits.h&gt;
  
  int main() {
      char a = 255;
      char b = -128;
      a = -128;
      b = 255;
      printf("size: %lu\n", sizeof(char));
      printf("min: %d\n", CHAR_MIN);
      printf("max: %d\n", CHAR_MAX);
  }
  </code></pre>
  
  <p>The printf-output is:</p>
  
  <pre><code>size: 1
  min: -128
  max: 127
  </code></pre>
  
  <p>How is that possible? The size of char is 1 Byte and the default char seems to be signed (-128...127). So how can I assign a value > 127 without getting an overflow warning (which I get when I try to assign -128 or 256)? Is gcc automatically converting to unsigned char? And then, when I assign a negative value, does it convert back? Why does it do so? I mean, all this implicitness wouldn't make it easier to understand. </p>
  
  <p>EDIT:</p>
  
  <p>Okay, it's not converting anything:</p>
  
  <pre><code>char a = 255;
  char b = 128;
  printf("%d\n", a);    /* -1 */
  printf("%d\n", b);    /* -128 */
  </code></pre>
  
  <p>So it starts counting from the bottom up. But why doesn't the compiler give me a warning? And why does it so, when I try to assign 256?</p>