Where can I find a listing of C++11 type prefixes/suffixes?
-
29-06-2021 - |
Question
Could somebody point me to a complete listing of language type prefixes/suffixes?
prefix examples:
auto s1 (u8"I'm a UTF-8 string.");
auto s2 (u"This is a UTF-16 string.");
auto s3 (U"This is a UTF-32 string.");
auto s4 (R"(RAW \ STRING " )");
auto s5 (L"wide string");
//etc..
//*I've only seen prefixes like this for strings.
suffix examples:
auto n1 = 7.2f;
auto n2 = 7.2d;
auto n3 = 100L;
auto n4 = 10000LL;
//etc..
All my search attempts send me to "making your own user defined literals".
Perhaps these instances have a specific name that I'm not aware of?
Solution
These are not "type" prefixes/suffixes, these are literal prefixes/suffixes, as they are applied on literals (string literals, number literals, ...). They don't have specific names, because they aren't that interesting ☺.
The built-in prefixes and suffixes in C++11 are:
Integers:
12U
,12L
,12UL
,12LU
,12LL
,12ULL
,12LLU
,12u
,12uL
,12Lu
,12uLL
,12LLu
,12l
,12Ul
,12lU
,12ll
,12Ull
,12llU
,12ul
,12lu
,12ull
,12llu
Floating points:
1.0f
,1.0F
,1.0l
,1.0L
Characters:
L'x'
,u'x'
,U'x'
Strings:
u8"xxx"
,u"xxx"
,U"xxx"
,L"xxx"
,R"(xxx)"
,u8R"(xxx)"
,uR"(xxx)"
,UR"(xxx)"
,LR"(xxx)"
In particular, 1.0d
is not a built-in C++11 suffix. Some compilers e.g. GCC may also have extensions for other number suffixes, see C floating point number notation.
Relevant lexical grammar:
(§2.14.2 Integer literals)
unsigned-suffix: one of
u U
long-suffix: one of
l L
long-long-suffix: one of
ll LL
(§2.14.4 Floating literals)
floating-suffix: one of
f l F L
(§2.14.3 Character literals)
character-literal:
'
c-char-sequence'
u'
c-char-sequence'
U'
c-char-sequence'
L'
c-char-sequence'
and
(§2.14.5 String literals)
string-literal:
encoding-prefixopt
"
s-char-sequenceopt"
encoding-prefixoptR
raw-stringencoding-prefix:
u8
u
U
L