• C

pointer value

i have a structure:


struct iorb_node {
   ...
   int *hook;
  ..
};

i want to set an integer value for hook (say for example, 2).  how do i do this correctly??
and once set, how would i access that value?
rawdribAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

efnCommented:
An integer can be converted to a pointer, so you can just code

someiorb_node.hook = 2;

You can access the value just by referring to the hook member, as in someiorb_node.hook.

Unless you are coding for a tiny embedded system with no operating system, it would be very unusual to do this kind of conversion.  Most operating systems are unlikely to let you access memory through a pointer with a value of 2, and the language definition makes no guarantees about what these operations will do.

I took your question literally, but maybe you wanted to work with the number the hook pointer addresses, not the pointer itself.  In that case, you need to use the dereferencing operator *, as in:

*(someiorb_node.hook) = 2;

if (*(someiorb_node.hook) == 2)
...

--efn
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rawdribAuthor Commented:
it is for an operating system device modules implimentation, thanks for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

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.