Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Pointers and Structures (http://www.go4expert.com/forums/pointers-and-structures-t14483/)

gk123987 10Oct2008 19:40

Pointers and Structures
 
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 10Oct2008 19:47

Re: Pointers and Structures
 
Is there any way by which we can access a function using the functions address alone?

oogabooga 10Oct2008 21:22

Re: Pointers and Structures
 
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).


All times are GMT +5.5. The time now is 21:58.