Jayesh Bhoi
Jayesh Bhoi

Reputation: 25865

Need to remove extra argument at function call

This is my typedef struct

//command look up table structure
typedef struct
{
    int commandCode;
    int  (*process_command) (...);
}cmdTableStruct;

Using int (*process_command) (...); i need to call appropriate function which i have assign to that if command code match.

ex.

static cmdTableStruct cmdTable[]=
{
 { 1123,testFunc},
 // more command in same manner
};

here it will call testFunc function if command code 1123 and argument of this function only one. Same it will call different functions but the argument type is different and argument is one.

Now using int (*process_command) (...); in stuct definition it give me error like

Error:  #xx: expected a type specifier

I can resolve this error by adding one known type argument

like

int  (*process_command) (int x,...);

But i don't want additional argument, i just want it will take one argument and call function with appropriate data type of argument.

is any suggestions?

Upvotes: 0

Views: 166

Answers (1)

Arjun Mathew Dan
Arjun Mathew Dan

Reputation: 5298

Posting my comment as an answer, u can consider this:

typedef struct
{
    int commandCode;
    int  (*process_command) (void *ptr);
}cmdTableStruct;

Make the argument to process_command to void *. Pass address of variable of whatever types you need for any specific case. Within each function, typecast to expected, copy to local variables of expected types and use.

Upvotes: 1

Related Questions