单引号作为大量分隔符?
Single quotes as separator in large number?
我一直在尝试编译 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
错误。
使用 -std=c++14
,因为分隔符是 C++14 的一项功能。参见: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]
我一直在尝试编译 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
错误。
使用 -std=c++14
,因为分隔符是 C++14 的一项功能。参见: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]