boost::uint32_t != std::uint32_t 用于 ARM 目标
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)
完全有可能是真的。这是两种可以具有相同宽度的不同类型。
不能保证两个 32 位无符号整数值的类型相同。
事实上,long
和int
可以是不同的类型,并且可以同时是32位值。 wchar_t
和 short
也是 16 位值。
从 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)
完全有可能是真的。这是两种可以具有相同宽度的不同类型。
不能保证两个 32 位无符号整数值的类型相同。
事实上,long
和int
可以是不同的类型,并且可以同时是32位值。 wchar_t
和 short
也是 16 位值。