C

Asked • 06/22/19

Why does the smallest int, −2147483648, have type 'long'?

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. printf("PRINTF(d) \ : %d\\n", -2147483648);tells me (`gcc -Werror -Wextra -Wall`): error: format specifies type 'int' but the argument has type 'long' [-Werror,-Wformat] printf("PRINTF(d) \ : %d\\n", -2147483648); ~~ ^~~~~~~~~~~ %ldBut if I use an int variable, everything is going well: int i; i = -2147483648; printf("%d", i);Why?EDIT:------I understood many points, and they were very interesting. Anyway, I guess `printf` is using the `<stdarg.h>` librairy and so, `va_arg(va_list ap, type)` should also return the right type. For `%d` and `%i`, obviously the type returned is an `int`. Does it change anything?

1 Expert Answer

By:

Keith B. answered • 06/28/19

Tutor
4.6 (22)

Software Engineer and Math Geek

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.