Where can I find a listing of C++11 type prefixes/suffixes?
Asked Answered
G

1

6

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?

Glyceride answered 1/9, 2012 at 7:12 Comment(0)
E
9

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-prefixopt R raw-string

encoding-prefix:

u8
u
U
L

Exemplification answered 1/9, 2012 at 7:40 Comment(3)
A mention of user-defined literals would be nice.Stope
@LucDanton: Well I believe OP already knows what user-defined literals are (s/he mentioned it in the second-last paragraph), so I just leave it out.Exemplification
What if someone else is interested in literals in a wider sense and stumble on that question via a search?Stope

© 2022 - 2024 — McMap. All rights reserved.