Search code examples
cintlanguage-lawyersigned

Is `int` always signed?


I always thought that in C, int stands for signed int ; but I have heard that this behavior is platform specific and in some platforms, int is unsigned by default. Is it true? What says the standard, and has it evolved over time?


Solution

  • You are quite right. As per C11 (the latest standard), chapter §6.7.2

    • int, signed, or signed int

    is categorized as same type (type specifiers, to be exact). So, int is the same as signed int.

    Also, re-iterating the same, from chapter §6.2.5/P4

    There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int. (These and other types may be designated in several additional ways, as described in 6.7.2.) [....]

    So, for any conforming environment, int stands for signed int and vice versa.