Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > What u mean by this statemnet ?.

Reply
Thread Tools

What u mean by this statemnet ?.

 
 
Umesh
Guest
Posts: n/a
 
      01-31-2006
what this statement &(*IR)->func means.

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

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      01-31-2006
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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
 
Michael Mair
Guest
Posts: n/a
 
      01-31-2006
Umesh wrote:
> 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
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
 
Reply With Quote
 
Umesh
Guest
Posts: n/a
 
      01-31-2006
Thank you
Michael.

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

if yes how compiler interpret this statement.

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      01-31-2006
Umesh said:
>
> is it **IR.func & (*IR)->func is same.how ?


No.

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

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
Umesh
Guest
Posts: n/a
 
      01-31-2006
(*IR)->func is equivalent to (**IR).func

Then how compiler interpret this two statement.

 
Reply With Quote
 
Vladimir S. Oka
Guest
Posts: n/a
 
      01-31-2006

Umesh wrote:
>Richard Heathfield wrote:
>> (*IR)->func is equivalent to (**IR).func

>
> 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

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      01-31-2006
Umesh wrote:

> (*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

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
weighted mean; weighted standard error of the mean (sem) C Barrington-Leigh Python 1 09-10-2010 02:03 AM
Re: What does this green blob mean? William W. Plummer Firefox 2 10-11-2004 01:13 PM
Re: What does this green blob mean? Leonidas Jones Firefox 2 10-11-2004 03:58 AM
middle click -- what does it mean? me Firefox 10 10-04-2004 01:29 AM
What the hell does this mean? jackd@morcor.com Firefox 2 07-11-2004 12:25 AM



Advertisments