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

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?
0
rawdrib
Asked:
rawdrib
1 Solution
 
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
 
rawdribAuthor Commented:
it is for an operating system device modules implimentation, thanks for your help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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