错误:整数常量上的后缀“i64”无效

时间:2014-09-05 19:36:45

标签: c++ compilation

编译时,我在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)

3 个答案:

答案 0 :(得分:4)

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

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

根据您关联的来源,gcc的正确后缀应为ll,但这需要SIZEOF_LONG_LONG == 8.

正如基思指出使用LL后缀可能比使用ll更好,因为它是等效的ll它很容易被误认为是11一个)甚至错误输入。

答案 1 :(得分:3)

看起来配置错误。

i64是特定于Microsoft的后缀,在INT64_MAX时会触发以这种方式定义SIZEOF___INT64 == 8的分支,而只有在包含src/win32/orconfig.h时才会触发

答案 2 :(得分:1)

你可以尝试:

#ifndef INT64_MAX
#define INT64_MAX 0x7fffffffffffffffLL
#endif