The following program fails to compile when cross-compiling from OS X to ARM:
#include <boost/cstdint.hpp>
#include <cstdint>
#include <type_traits>
static_assert(std::is_same<std::uint32_t, boost::uint32_t>::value, "");
int main() { }
I'm building with
arm-none-eabi-g++ -I /path/to/boost -std=c++11 -c main.cpp
where
> 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]
To try and diagnose the issue further, I tried the following trick:
template <typename T> struct show;
using A = show<std::uint32_t>::invalid;
using B = show<boost::uint32_t>::invalid;
The compiler gives me the following error message, which indicates that std::uint32_t == long unsigned int
, while 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;
I find this situation very surprising. Shouldn't uint32_t
always represent exactly the same type (a 32-bit width unsigned integer), regardless of the system on which we are? Is this a bug in Boost or simply me misunderstanding something?
uint32_t
should always represent a 32-bit width unsigned integer, yes.
But it's perfectly possible for sizeof(long unsigned int) == sizeof(unsigned int)
to be true. Those are two different types that can have the same width.
There is no guarantee that two 32 bit unsigned integer values are the same type.
In fact, long
and int
can be distinct types, and both can be 32 bit values, at the same time. Ditto for wchar_t
and short
being 16 bit values.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.