What u mean by this statemnet ?.

U

Umesh

what this statement &(*IR)->func means.

where IR is the pointer to structure & func is pointer to fuction.
func is the member of structure.
 
R

Richard Heathfield

Umesh said:
what this statement &(*IR)->func means.

This takes the address of the func object that is a member of a structure
that is pointed to by a pointer which is in turn pointed to by IR.

Let's start with IR.

IR is a pointer to a pointer to a struct.
*IR is a pointer to a struct.
(*IR)-> dereferences the struct.
(*IR)->func refers to the func member of the struct.
&(*IR)->func takes the address of the func member.
where IR is the pointer to structure

It isn't. At least, if it is, the compiler will emit a diagnostic for the
above code.
 
M

Michael Mair

Umesh said:
what this statement &(*IR)->func means.

where IR is the pointer to structure & func is pointer to fuction.
func is the member of structure.

a->b is the same as (*a).b. Thus, IR cannot be a pointer
to struct but is a pointer to a pointer to struct, as
it is dereferenced twice:
(*IR)->func means (**IR).func
Now, you apply the address operator.
This gives you the address where the function pointer (**IR).func
is stored.

Observe:

#include <stdio.h>

int main (void)
{
struct test {
int filler;
void (*func)(void);
} instance, *pinst, **IR;
int offset = offsetof(struct test, func);

instance.filler = 0;
instance.func = NULL;
pinst = &instance;
IR = &pinst;

printf("inst: %p func: %p %p\n", (void *)(&instance),
(void *)(&instance.func), (void *)(&(*IR)->func));
printf("distance: %d %d\n", (int) offset,
(int) ((unsigned char*)(&(*IR)->func)-(unsigned char*)(*IR)));

return 0;
}


Cheers
Michael
 
U

Umesh

Thank you
Michael.

is it **IR.func & (*IR)->func is same.how ?

if yes how compiler interpret this statement.
 
U

Umesh

(*IR)->func is equivalent to (**IR).func

Then how compiler interpret this two statement.
 
V

Vladimir S. Oka

Umesh said:
Then how compiler interpret this two statement.

Please properly quote who said what. The first line above was by
Richard, and the second is your question, as far as I can see, so the
answer to your question is:

The compiler interprets these two in exactly the same way (i.e.
produces exactly the same code/behaviour). The two are obviously not
the /same/ (not spelled the same, if you want), but they mean /the same
thing/ to the compiler. Think of a->b as shorthand for (*a).b, and
things may be clearer. Thus:

(**IR).func <=> (*(*IR)).func <=> (*IR)->func

Cheers

Vladimir
 
D

Default User

Umesh said:
(*IR)->func is equivalent to (**IR).func

Then how compiler interpret this two statement.

Looks like you are trying to quote using the Google interface. The
information below may be of use.



Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top