Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single quotes as separator in large number?

I've been trying to compile parts of some code from the MAME project, and I am running into an issue compiling this section in attotime.h:

// core components of the attotime structure
typedef s64 attoseconds_t;
typedef s32 seconds_t;

// core definitions
constexpr attoseconds_t ATTOSECONDS_PER_SECOND_SQRT = 1'000'000'000;
constexpr attoseconds_t ATTOSECONDS_PER_SECOND = ATTOSECONDS_PER_SECOND_SQRT * ATTOSECONDS_PER_SECOND_SQRT;
constexpr attoseconds_t ATTOSECONDS_PER_MILLISECOND = ATTOSECONDS_PER_SECOND / 1'000;
constexpr attoseconds_t ATTOSECONDS_PER_MICROSECOND = ATTOSECONDS_PER_SECOND / 1'000'000;
constexpr attoseconds_t ATTOSECONDS_PER_NANOSECOND = ATTOSECONDS_PER_SECOND / 1'000'000'000;

constexpr seconds_t ATTOTIME_MAX_SECONDS = 1'000'000'000;

Which gives the error:

In file included from ~/git/mame/src/emu/emu.h:32,
                 from main.cpp:1:
~/git/mame/src/emu/attotime.h:54:56: warning: multi-character character constant [-Wmultichar]
 constexpr attoseconds_t ATTOSECONDS_PER_SECOND_SQRT = 1'000'000'000;
                                                        ^~~~~
~/git/mame/src/emu/attotime.h:54:64: warning: missing terminating ' character
 constexpr attoseconds_t ATTOSECONDS_PER_SECOND_SQRT = 1'000'000'000;
                                                                ^
~/git/mame/src/emu/attotime.h:54:64: error: missing terminating ' character
 constexpr attoseconds_t ATTOSECONDS_PER_SECOND_SQRT = 1'000'000'000;
                                                                ^~~~~
compilation terminated due to -Wfatal-errors.
make: *** [<builtin>: main.o] Error 1

I have not modified the code or includes, but I am compiling it my own Makefile. I have never seen this syntax, and couldn't find anything about it online.

Is there a g++ flag which enables this? I know I can use -Wno-multichar to get rid if that warning, but there's still the missing terminating ' character error.

like image 542
sealj553 Avatar asked Jan 01 '23 23:01

sealj553


1 Answers

Use -std=c++14, as separator is a C++14 feature. See: https://en.cppreference.com/w/cpp/language/integer_literal

Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler. [since C++14]

like image 50
geza Avatar answered Jan 07 '23 13:01

geza