What u mean by this statemnet ?.

Discussion in 'C Programming' started by Umesh, Jan 31, 2006.

  1. Umesh

    Umesh Guest

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

    where IR is the pointer to structure & func is pointer to fuction.
    func is the member of structure.
    Umesh, Jan 31, 2006
    #1
    1. Advertising

  2. 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)
    Richard Heathfield, Jan 31, 2006
    #2
    1. Advertising

  3. Umesh

    Michael Mair Guest

    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.
    Michael Mair, Jan 31, 2006
    #3
  4. Umesh

    Umesh Guest

    Thank you
    Michael.

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

    if yes how compiler interpret this statement.
    Umesh, Jan 31, 2006
    #4
  5. 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)
    Richard Heathfield, Jan 31, 2006
    #5
  6. Umesh

    Umesh Guest

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

    Then how compiler interpret this two statement.
    Umesh, Jan 31, 2006
    #6
  7. 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
    Vladimir S. Oka, Jan 31, 2006
    #7
  8. Umesh

    Default User Guest

    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.
    Default User, Jan 31, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pratip Mukherjee

    Help: what does this VHDL code mean?

    Pratip Mukherjee, Jun 22, 2005, in forum: VHDL
    Replies:
    16
    Views:
    1,276
    Kim Enkovaara
    Jun 27, 2005
  2. methi
    Replies:
    1
    Views:
    840
    info_
    Jun 23, 2005
  3. Lyn
    Replies:
    5
    Views:
    526
    Terry Michaels
    May 6, 2004
  4. Weng Tianxiang

    Mean value filter

    Weng Tianxiang, Dec 7, 2005, in forum: VHDL
    Replies:
    1
    Views:
    1,395
    Senthil
    Dec 12, 2005
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    1,198
    Tim Leslie
    Sep 10, 2010
Loading...

Share This Page