Reputation: 1
At first I'm sorry for my English:) So, I have a structure and variable
typedef struct
{
GHEADER m_Header;
BYTE *m_Buf;
Addr *m_Abonent;
}__attribute__((packed)) PACKET;
unsigned char* uc_ptr;
I need to send to some function unsigned char pointer argument. I tried to use reinterpret_cast
to cast a pointer to PACKET
type to unsigned char*
.
PACKET* t_PACKET;
uc_ptr = reinterpret_cast<unsigned char*>(t_PACKET);
But then I tried
std::cout << *uc_ptr << std::endl;
I don't see anything. Why? And how to cast this correctly?
Upvotes: 0
Views: 1287
Reputation: 308452
When you use <<
to output a char
you get a single character written to the output. Many characters such as \0
do not show up on the console.
Try this instead to see what I mean:
std::cout << static_cast<unsigned int>(*uc_ptr) << std::endl;
You'll need a loop to get all of the bytes in the structure.
Upvotes: 3