I've been experimenting with reinterpret_cast and boost integer. I've
found that I can correctly cast uint16_t, uint32_t and uint64_t,
however, when I try to do that with a uint8_t or int8_t (both one
byte), it doesn't seem to work. Below is some sample code that
demonstrates the issue.
This is not really boost specific, it's probably just my
misunderstanding/misuse of reinterpret_cast, but if anyone here could
point me in the right direction, I'd appreciate it.
Thanks,
Brad
#include <iostream>
#include
void process_uint16_t( const std::string& bytes )
{
const boost::uint16_t * data_ptr;
boost::uint16_t data;
data_ptr = reinterpret_cast(bytes.data());
data = *data_ptr;
std::cout << data << std::endl;
}
void process_uint8_t( const std::string& bytes )
{
const boost::uint8_t * data_ptr;
boost::uint8_t data;
data_ptr = reinterpret_cast(bytes.data());
data = *data_ptr;
std::cout << data << std::endl;
}
int main()
{
std::string r1("\u001F\u001F");
std::string r("\u001F");
process_uint16_t(r1);
process_uint8_t(r);
return 0;
}