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?
-
1Didn't you just answer your question? – Rakete1111 Oct 11 '17 at 19:21
-
See http://en.cppreference.com/w/cpp/language/implicit_conversion – Bathsheba Oct 11 '17 at 19:23
-
I think your question is "how do I determine the type of an integer literal in a particular compiler implementation?" right? – nicomp Oct 11 '17 at 19:25
-
2In the section you refer to is says *"The type of an integer literal is the first of the corresponding list in Table 7 in which its value can be represented."*. So 123456 is an int if it fits, otherwise it is long or long long. – Bo Persson Oct 11 '17 at 19:33
-
Does this answer your question? [Type of integer literals not int by default?](https://stackoverflow.com/questions/8108642/type-of-integer-literals-not-int-by-default) – phuclv Jan 17 '23 at 14:57
1 Answers
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
.

- 101,917
- 9
- 204
- 274