单引号用作大量的分隔符吗?

时间:2018-08-26 14:33:14

标签: c++ syntax emulation

我一直在尝试从MAME项目中编译部分代码,并且在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;

哪个给出错误:

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

我尚未修改代码或包含代码,但正在将其编译为自己的Makefile。我从未见过这种语法,也无法在线找到任何有关它的信息。

是否有启用此功能的g ++标志?我知道我可以使用-Wno-multichar来消除该警告,但是仍然存在missing terminating ' character错误。

1 个答案:

答案 0 :(得分:5)

使用-std=c++14,因为分隔符是C ++ 14的功能。参见:https://en.cppreference.com/w/cpp/language/integer_literal

  

可以在数字之间插入可选的单引号(')作为分隔符。它们被编译器忽略。 [自C ++ 14起]