rmt*_*eis 66 c++ cstdint uint32-t
我正在尝试编译2007年编写的C++软件包,我收到了这个错误:
error: ‘uint32_t’ does not name a type
这是在使用g ++ 4.5.2的64位Ubuntu中发生的.它使用g ++ 4.1.2在64位CentOS上编译良好.
#include我缺少一个或一个编译器标志吗?或者,我应该typedef用来分配uint32_t一个size_t或者一个unsigned int?
sel*_*bie 134
你需要包含stdint.h
#include <stdint.h>
Run Code Online (Sandbox Code Playgroud)
pla*_*sma 32
你需要#include <cstdint>,但这可能并不总是奏效.
问题是某些编译器通常会在这些标准到位之前自动导出在各种标头或提供的类型中定义的名称.
现在,我说"可能并不总是有效".那是因为cstdint标头是C++ 11标准的一部分,并不总是在当前的C++编译器上可用(但通常是).stdint.h头是C等价物,是C99的一部分.
为了获得最佳的可移植性,boost/cstdint.hpp如果您愿意使用boost ,我建议使用Boost的标头.否则,你可能会逃脱#include'ing <cstdint>.
我在Mac OSX 10.6.8上也遇到了同样的问题,遗憾的是添加#include <stdint.h>或<cstdint.h>相应的文件并没有解决我的问题.然而,经过更多的搜索,我发现这个解决方案建议添加#include <sys/types.h>哪个适合我!
其他答案假设您的编译器符合C++ 11.如果是的话,这很好.但是,如果您使用较旧的编译器呢?
我在网上的某个地方拿起了下面的黑客.它对我来说效果很好:
#if defined __UINT32_MAX__ or UINT32_MAX
#include <inttypes.h>
#else
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;
#endif
Run Code Online (Sandbox Code Playgroud)
当然,它不便携.但它可能适用于您的编译器.