
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

I can make the cast work by storing it in a uint16_t or larger type:
void process_uint8_t( const std::string& bytes )
{
const boost::uint16_t * data_ptr;
boost::uint16_t data;
data_ptr = reinterpret_cast

On Sun, Feb 5, 2012 at 7:06 AM, Brad Tilley
I can make the cast work by storing it in a uint16_t or larger type:
void process_uint8_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 << "," << sizeof(data) << std::endl; }
I thought this would work in a uint8_t as well, but it doesn't.
Thanks,
Brad
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
What doesn't work about it? The std iostreams print char types as (extended) ascii characters. What if you cast the type to a wider integer just when printing? Brian

What doesn't work about it? The std iostreams print char types as (extended) ascii characters. What if you cast the type to a wider integer just when printing?
Brian
Thanks Brian. I wasn't aware that iostream would do that. You're
right, uint8_t is big enough, iostream just prints out the extendend
ASCII char rather than the int on std::cout. This works:
void process_uint8_t( const std::string& bytes )
{
const boost::uint8_t * data_ptr;
boost::uint8_t data;
data_ptr = reinterpret_cast
participants (2)
-
Brad Tilley
-
Brian Budge