How to convert a char pointer to unsigned short

Hello,
I am working on this project where I receive a char pointer, but need to cast it to an unsigned short. Below is an example of the code, I am trying to add code to methodB. Also I am not understanding why pointer in methodA is passed as a char and than it is passed to methodB as void. Does this have something to do with how I am casting.

Any help with be greatly appreceiated!!!!

1
2
3
4
5
6
7
8
9
10
 methodA(char *ptr)
{
  methodB(&bufer[0])
}
methodB(void *ptr)
{

 unsigned short *pBuffer = (unsigned short *) ptr;
}
methodB is saying that it can accept a pointer of any type.

This is very unsafe code. char and short have different lengths. You have no guarantee that the caller has reserved at least sizeof(short) bytes when he allocated what ptr points to. (I'm assuming ptr and buf are the same thing in your example).

Topic archived. No new replies allowed.