문제

Below is the sample structure

struct tipc_port {
        void *usr_handle;
        spinlock_t *lock;

};

Below is the function call which returns a pointer to the above structure

struct tipc_port *tipc_get_port(const u32 ref);

now I want to store this pointer to struct in some variable and this variable would be passed to some other function.

how to declare this variable which would hold the pointer to struct returned by the above function.

Thanks in Advance :)

도움이 되었습니까?

해결책

In C you declare variables as:

type varname;

or

struct struct_name varname;

So in your case you need:

struct tipc_port * variable;

다른 팁

One way for doing that is to declare your own type :

typedef struct{
  void *usr_handle;
  spinlock_t *lock;
}tipc_port_t;

And then use it as you may use any other common types :

tipc_port_t* tipc_get_port(const u32 ref);

And on your code :

tipc_port_t *yourStructPointer;
u32 yourRef;

yourStructPointer = tipc_get_port(yourRef);
[...]

Or :

tipc_port_t yourStructPointer;
u32 yourRef;

&yourStructPointer = tipc_get_port(yourRef);
[...]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top