Pointers and Structures

gk123987's Avatar
Go4Expert Member
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 ?
gk123987's Avatar
Go4Expert Member
Is there any way by which we can access a function using the functions address alone?
oogabooga's Avatar
Ambitious contributor
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");


Quote:
Is there any way by which we can access a function using the functions address alone?
A function name is an address (i.e., a pointer).