Are digit delimiters preceding hexadecimal or binary numbers allowed?

C ++ 14 introduced the concept of numeric delimiters to literals along lines 3'141'592'653'589 . Now this is a great feature for readable code, but I was wondering if it allowed quotes before the numeric part of the literal 0x/0b -type. I think that:

 unsigned int topThreeBits = 0b'1110'0000; unsigned int hexNum = 0x'dead'beef; 

more readable than one that does not have a leading separator:

 unsigned int topThreeBits = 0b1110'0000; unsigned int hexNum = 0xdead'beef; 

because it clearly defines the base of the numbers.

Since I don't have a C ++ 14 compiler yet, I need to confirm something if this is allowed.

I know this doesn't make sense for non-prefix numbers like '123'456 , especially since the parser didn't know if it should be a char variable or a numeric literal.

But for prefix literals, I see no confusion about what the token means at the point where the first one arrives - 0x/0b already dictated this as a numeric literal.

+7
c ++ c ++ 14 digit-separator
source share
1 answer

If we look at the grammar from the C ++ 14: N4140 draft section 2.14.2 [lex.icon], it is not allowed immediately after the base indicator of hexadecimal or binary literals:

 binary-literal: 0b binary-digit 0B binary-digit binary-literal 'opt binary-digit [...] hexadecimal-literal: 0x hexadecimal-digit 0X hexadecimal-digit hexadecimal-literal 'opt hexadecimal-digit 

Although, octal literals allow the separator after the base indicator:

 octal-literal: 0 octal-literal 'opt octal-digit 

We can also test the use of one of the online compilers that C ++ 14 compilers provide, such as Coliru or Wandbox .

The problem of the Evolution working group that tracked this change was issue 27: N3781 Single quote-marker as a digit separator, N3661, N3499 Digitizer, N3448 Painless division of digits . I do not see the obvious justification for this design decision, perhaps this is an exclusively literal interpretation of the digit separator.

Note, we can find a list of draft standards from Where can I find current standard C or C ++ documents? .

+8
source share

All Articles