Pointers and type casting

I had put 99 on hci_ll_pkt_val[0], but I am not getting this value of 99 on hci_ll_pkt_arr[0] ??

1
2
3
4
5
6
7
8
9
10
unsigned char* hci_ll_pkt_arr;                                 
int* hci_ll_pkt_val;      

cout<<"@"<<sc_time_stamp()<<"\t\t hci_ll_pkt_val = "<<hci_ll_pkt_val[i]   <<"\n";                              
          
hci_ll_pkt_arr = reinterpret_cast<unsigned char*>(hci_ll_pkt_val); 
 
cout<<"@"<<sc_time_stamp()<<"\t\t hci_ll_pkt_arr = "<<hci_ll_pkt_arr[0]<<"\n";                              
  
  



Regards
cam
hci_ll_pkt_arr is an array of chars, not ints. So when cout prints out that array element, it will display it as a char. It will display the character with an ASCII code value of 99.
Last edited on
a pointer cast does not change anything pointed to.

in other words: you have an unsigned char pointer that points to a sequence of ints. You need to know how the ints are organized in memory in order to tell what the output is when used as unsigned char
Topic archived. No new replies allowed.