• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

unsigned short

I want to go back and forth from an unsigned short (temp) as a pointer to just an unsigned short (num), but ....
temp = (unsigned short*)num;
doesn't work or vice versa.
  • 3
1 Solution
I'm having trouble following you, but I assume that temp is declared as "unsigned short *" and num is some sort of integral type, like short.  Right?  then

unsigned short *temp = *(unsigned short **) #

that is, get a pointer to num &num), convert the pointer to be a pointer to a unsigned short pointer (pointer to "unsigned short *" is "unsigned short **"), then derference the pointer.
Any of these should work:

temp = #

*temp = num;

num = *temp;
The only work if temp is a pointer to the same type that num is.  I'm guessing that is not the case.
Hmmm.  As I re-read I'm beginning to wonder if Eric is right.  If num is an unsigned short and temp is just a pointer to an unsigned short, then you should just do

temp = &num.

The "&" means "generate a pointer to" the item on the right.  If this is what you need, you should reject my answer and award the points to Eric.
jtm082698Author Commented:
Thanks for putting me on the right track, it was the ole "can't see the forest for the trees" type thing.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now