Search code examples
c++c++11standardsliterals

Where in the C++ standard can I read what type an integer literal is?


In chapter "lexical conventions/Literals" it simply mentions that without suffix, it could be any of int, long int or long long int. Where does it explicitly state it being implementation defined or - if not - what type it is?


Solution

  • In lex.icon, the second paragraph, there is a table. Before the table it says

    The type of an integer literal is the first of the corresponding list in Table 6 in which its value can be represented.

    And then in the table, under decimal constants, it lists, in order, int, long int, long long int. So according to the above statement, if it can be represented by an int, then it's an int. If it can't be represented by an int, but it can be represented by a long int, then it's a long int. And if it can't be represented by a long int but it can be represented by a long long int, then it's a long long int.

    There are different rules for octal and hexadecimal constants, which allow them to be unsigned types, ordered for priority as int, unsigned int, long int, unsigned long int, long long int, unsigned long long int.