?
Solved

unsigned short

Posted on 1998-09-15
5
Medium Priority
?
355 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 120 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

800 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