c++ - 错误 : invalid suffix "i64" on integer constant

标签 c++ compilation

编译 tor 时,在 torint.h 中出现以下错误...

src\tor\torint.h:190: error: invalid suffix "i64" on integer constant
 #define INT64_MAX 0x7fffffffffffffffi64
               ^

具体在下面这一行。

https://github.com/arlolra/tor/blob/master/src/common/torint.h#L190

上面链接的代码是下面代码的第二行...

#ifndef INT64_MAX
#define INT64_MAX 0x7fffffffffffffffi64
#endif

我正在使用 gcc 4.8.2 使用 MingW32 在 Windows 7 64 位上构建。 gcc -v 的完整输出如下。我读到这可能是一个环境问题,但无法找到解决方案。任何有关如何解决此问题的建议都将不胜感激。

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw32/bin/../libexec/gcc/i686-w64-mingw32/4.8.2/lto-wra
pper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-4.8.2/configure --host=i686-w64-mingw32 --buil
d=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/c
/mingw482/i686-482-posix-dwarf-rt_v3-r2/mingw32 --with-gxx-include-dir=/mingw32/
i686-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib
--enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=ye
s --enable-threads=posix --enable-libgomp --enable-lto --enable-graphite --enabl
e-checking=release --enable-fully-dynamic-string --enable-version-specific-runti
me-libs --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --di
sable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --en
able-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-
werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tun
e=generic --with-libiconv --with-system-zlib --with-gmp=/c/mingw482/prerequisite
s/i686-w64-mingw32-static --with-mpfr=/c/mingw482/prerequisites/i686-w64-mingw32
-static --with-mpc=/c/mingw482/prerequisites/i686-w64-mingw32-static --with-isl=
/c/mingw482/prerequisites/i686-w64-mingw32-static --with-cloog=/c/mingw482/prere
quisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='i
686-posix-dwarf, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.ne
t/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw482/i686-482-posix-dwarf-rt_v3-
r2/mingw32/opt/include -I/c/mingw482/prerequisites/i686-zlib-static/include -I/c
/mingw482/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/
c/mingw482/i686-482-posix-dwarf-rt_v3-r2/mingw32/opt/include -I/c/mingw482/prere
quisites/i686-zlib-static/include -I/c/mingw482/prerequisites/i686-w64-mingw32-s
tatic/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw482/i686-482-posix-dwarf-rt_v3
-r2/mingw32/opt/lib -L/c/mingw482/prerequisites/i686-zlib-static/lib -L/c/mingw4
82/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
Thread model: posix
gcc version 4.8.2 (i686-posix-dwarf, Built by MinGW-W64 project)

最佳答案

i64 不是标准整数文字后缀,因此这必须是编译器扩展。 2.14.2 整数文字 部分中的 C++ 标准草案定义了以下整数文字后缀:

integer-suffix:
    unsigned-suffix long-suffixopt
    unsigned-suffix long-long-suffixopt
    long-suffix unsigned-suffixopt
    long-long-suffix unsigned-suffixopt
unsigned-suffix: one of
    u U
long-suffix: one of
    l L
long-long-suffix: one of
    ll LL

我们可以从他们的 C++ Integer Constants 中看到 Microsoft 确实允许在 C++ 中使用这样的后缀页面。

根据您链接到的源代码,gcc 的正确后缀应该是 ll,但这需要 SIZEOF_LONG_LONG == 8。

正如 Keith 指出的那样,使用 LL 后缀可能比使用 ll 更好,因为它是等效的,而 ll 很容易被误认为是11(一个)甚至打错了。

关于c++ - 错误 : invalid suffix "i64" on integer constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25692848/

相关文章:

c++ - 当(CUDA 7.5 的)nvcc/cudafe++ 因段错误而崩溃时我该怎么办?

Java - 解释型还是编译型?

python - Boost.Python 快速入门链接器错误

c++ - 递归函数引起的栈溢出

c++ - Visual Studio 从预定义字符串宏中抛出 "undeclared identifier"

jquery - 图像处理编程

c++ - 如何在应该失败的CMake中实现编译测试?

c++ - 绕过 C++/STL 中的容器协变

c++ - 使一个类可用于其他程序

java - 为什么会出现编译错误 "org/codehaus/groovy/control/CompilationFailedException"?