[英]boost::uint32_t != std::uint32_t for ARM target
从OS X到ARM交叉编译时,以下程序无法编译:
#include <boost/cstdint.hpp>
#include <cstdint>
#include <type_traits>
static_assert(std::is_same<std::uint32_t, boost::uint32_t>::value, "");
int main() { }
我正在与
arm-none-eabi-g++ -I /path/to/boost -std=c++11 -c main.cpp
哪里
> arm-none-eabi-g++ --version
arm-none-eabi-g++ (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release)
[ARM/embedded-4_9-branch revision 224288]
为了进一步诊断问题,我尝试了以下技巧:
template <typename T> struct show;
using A = show<std::uint32_t>::invalid;
using B = show<boost::uint32_t>::invalid;
编译器给我以下错误消息,该消息指示std::uint32_t == long unsigned int
,而boost::uint32_t == unsigned int
:
main.cpp:8:32: error: 'invalid' in 'struct show<long unsigned int>' does not name a type
using A = show<std::uint32_t>::invalid;
^
main.cpp:9:34: error: 'invalid' in 'struct show<unsigned int>' does not name a type
using B = show<boost::uint32_t>::invalid;
我发现这种情况非常令人惊讶。 uint32_t
总是代表完全相同的类型(32位宽度的无符号整数),而不管我们所处的系统是什么? 这是Boost中的错误还是仅仅是我误解了某些东西?
uint32_t
应该始终表示32位宽度的无符号整数,是的。
但是,很有可能sizeof(long unsigned int) == sizeof(unsigned int)
为true。 这是两种可以具有相同宽度的不同类型。
不能保证两个32位无符号整数值是同一类型。
实际上, long
和int
可以是不同的类型,并且可以同时是32位值。 wchar_t
和short
同上是16位值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.