This code is working fine in c++.I need the solution for C.
This is my sample.
FileName:Mail.c
This is the declaration I made in the file mail.c
#ifdef __cplusplus
typedef int (__cdecl *SetIpAddressFun)(char* , int , int );
typedef bool (__cdecl *SendMailFun)(char * , char *);
#endif
I used this function pointers in the function called func() in the same file mail.c
void func()
{
SendMailFun sendMailFuncPtr;
SetIpAddressFun setIpAddressFuncPtr;
}
EDIT
If i remove the #ifdef lines in the file mail.c then it is showing the following error.
error C2143: syntax error : missing ')' before '__cdecl'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(138) : error C2143: syntax error : missing '{' before '__cdecl'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(138) : error C2059: syntax error : ')'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(138) : error C2165: 'left-side modifier' : cannot modify pointers to data
ERROR
List of errors happened while compiling in c.
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1615) : error C2065: 'SendMailFun' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1615) : error C2146: syntax error : missing ';' before identifier 'sendMailFuncPtr'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1615) : error C2065: 'sendMailFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1616) : error C2065: 'SetIpAddressFun' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1616) : error C2146: syntax error : missing ';' before identifier 'setIpAddressFuncPtr'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1616) : error C2065: 'setIpAddressFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1625) : error C2065: 'setIpAddressFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1625) : error C2065: 'SetIpAddressFun' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1625) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1626) : error C2065: 'setIpAddressFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1626) : warning C4047: '!=' : 'void *' differs in levels of indirection from 'int'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1628) : warning C4013: 'setIpAddressFuncPtr' undefined; assuming extern returning int
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1630) : error C2065: 'sendMailFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1630) : error C2065: 'SendMailFun' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1630) : error C2146: syntax error : missing ';' before identifier
This is because when you declared the function
you do it conditionally only for __cplusplus which is typically not defined when compiling C files
EDIT
I think your second problem is to do with the presence of bool which to my knowledge is not C keyword. Considering replacing it with an int