Milan Shah Milan Shah - 1 month ago 12
C Question

Expected identifier before token in function pointer

typedef enum
{
TCP = 1,
UDP
}protocol;

typedef enum
{
DLL_Operation = 1,
MT_Operation,
Fork_Operation,
IPC_Operation
}msgc;

struct f
{
int seqNo;
protocol p;
msgc m;
protocol q;
int PayLoadSize;
void (*payload_ptr)();
};


This is my structure which i am using...

Now i am assigning address of function in that function pointer defining in strucutre...

if(f2.m == 1)
{
f2.(*payload_ptr) = DLL;
f2.payload_ptr();
}
else if(f2.m == 2)
{
f2.(*payload_ptr) = MT;
f2.payload_ptr();
}
else if(f2.m == 3)
{
f2.(*payload_ptr) = Fork;
f2.payload_ptr();
}
else
{
f2.(*payload_ptr) = IPC;
f2.payload_ptr();
}


in compiling this program... it is showing error like..

error: expected identifier before ‘(’ token

f2.(*payload_ptr) = DLL;

& same for all condition.... what is the solution..

this DLL, MT all are some function which i define for certain operation...

Jay Jay
Answer

You are assigning the values to function pointers wrongly.

It should be like below for all the cases

if(f2.m == 1)
{                                                                           
    f2.payload_ptr = DLL;
    f2.payload_ptr();
}

Please ensure that functions like DLL are of type void DLL();

Comments