Solved

unsigned short

Posted on 1998-09-15
5
349 Views
Last Modified: 2010-04-02
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.
0
Comment
Question by:jtm082698
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 40 total points
ID: 1172779
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.
0
 

Expert Comment

by:eric_m
ID: 1172780
Any of these should work:

temp = #

*temp = num;

num = *temp;
0
 
LVL 22

Expert Comment

by:nietod
ID: 1172781
The only work if temp is a pointer to the same type that num is.  I'm guessing that is not the case.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1172782
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.
0
 

Author Comment

by:jtm082698
ID: 1172783
Thanks for putting me on the right track, it was the ole "can't see the forest for the trees" type thing.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question