Why does the smallest int, −2147483648, have type 'long'?
<p>For a school project, I've to code the C function printf. Things are going pretty well, but there is one question I can't find a good answer to, so here I am.</p>

<pre><code>printf("PRINTF(d) \t: %d\n", -2147483648);
</code></pre>

<p>tells me (<code>gcc -Werror -Wextra -Wall</code>):</p>

<pre><code>   error: format specifies type 'int' but the argument has type 'long'
      [-Werror,-Wformat]
        printf("PRINTF(d) \t: %d\n", -2147483648);
                              ~~     ^~~~~~~~~~~
                              %ld
</code></pre>

<p>But if I use an int variable, everything is going well:</p>

<pre><code>int i;

i = -2147483648;
printf("%d", i);
</code></pre>

<p>Why?</p>

<h2>EDIT:</h2>

<p>I understood many points, and they were very interesting. Anyway, I guess <code>printf</code> is using the <code>&lt;stdarg.h&gt;</code> librairy and so, <code>va_arg(va_list ap, type)</code> should also return the right type. For <code>%d</code> and <code>%i</code>, obviously the type returned is an <code>int</code>. Does it change anything?</p>