我已经写了一个最简单的测试问题:
#include <sys/types.h>
int main(int argc, char** argv) {
off_t l = 0;
return 0;
}
以下内容可行:
g++ test.cpp
。但是,如果我尝试使用c++11编译,我会得到以下错误提示: c:\test>g++ -std=c++11 test.cpp。
test.cpp: In function 'int main(int, char**)':
test.cpp:5:2: error: 'off_t' was not declared in this scope
test.cpp:5:8: error: expected ';' before 'l'
test.cpp:6:9: error: 'l' was not declared in this scope
有人能解释一下这是为什么吗?我感到烦恼的原因是,我正在尝试在我的C++11代码中使用zlib库。库zlib.h经常使用off_t。
我的编译器版本是:gcc 4.7.2
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.7.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.7.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1-with-cxx --enable-version-specific-runtime-libs -build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.7.2 (GCC)
g++ -E test.cpp > test.c
和g++ -std=c++11 -E test.cpp > test.c
我可以看到,如果没有加上c++11标准,代码中会有以下定义:typedef long _off_t; typedef _off_t off_t;
而使用了std=c++11标准后,只有以下定义:typedef long _off_t;
- odedsh