Pointers and Structures

Discussion in 'C' started by gk123987, Oct 10, 2008.

  1. gk123987

    gk123987 New Member

    Joined:
    Sep 9, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    I have a complex query,

    I have a structure some thing like this,

    typedef struct mod_Definition_T_Tag
    {
    int x;
    char y;
    float p;
    } mod_Definition_T;

    if in the code if the declaration is made as follows:

    typedef mod_Definition_T *(*create_func_t)(const char *config_str);

    what does this indicate or how do we put them in plain english statement ?
     
  2. gk123987

    gk123987 New Member

    Joined:
    Sep 9, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Is there any way by which we can access a function using the functions address alone?
     
  3. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    typedef mod_Definition_T *(*create_func_t)(const char *config_str);

    This declares a function pointer type called "create_func_t".
    It takes a const char* as an argument and returns a mod_Definition_T *.

    A simpler example of a function pointer declaration is:

    typedef int (*func) (int);

    This declares a function pointer type called func which takes an int
    and returns an int. You define function pointer variables from it like this:

    func a, b, c; // a, b, and c are function pointers of type func.

    And you can use the function pointers just like regular function names:

    int x = a(5);

    Your original example might be used something like this:

    create_func_t cft;
    mod_Definition_T *mdt = cft( "abcdefg");


    A function name is an address (i.e., a pointer).
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice