Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function pointers within structures

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
GB
struct com {
char nm[COMMAX];
void (*handler)();
};

How do i call the Function above, i have located the appropiate node of my structure using a name search. Now i want to call the function pointer, which will call a void method. The method name is stored in the struct as follows:

struct com comlist[COMS] =
{
{"LOOK",look},
{"L",look},

etc.......
 
When u initialize the struct variable with the function names, it stores the address in the respective instances of the structure array. Using an index and the function pointer name will suffice. like this:

Code:
comlist[i].handler();

Where 'i' holds the index for the FOUND location of the name. I don't believe u didnt try this before asking!;-)

Chow!

Roy.
user.gif
 
Okay, i have got the function to return the function pointer, but how do i name the function so that it knows it will return a function pointer?

I cannot name it void?
 
U need the function signature I guess. It should be someting like:

void (*funName(void))(void)

This is a function that will return a function pointer to a function which takes nothing and returns nothing.

I hope u got it!

have fun coding...

J Roy
user.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top