K
Klaus Schneider
Hi all!
In a C library compiled with gcc there is a pointer to a function defined
and called from within the library. Now I'm using that library in a C++
project and I'd like to set this function pointer to a C++ function. Do I
have to set the C++ function __attribute__((cdecl)) ? Are there any other
things I have to worry about? See example code below.
Thanks very much,
Klaus
Example Code:
-----------------------------------------------------
*** lib.c (compiled with gcc and linked to a library):
void (* logfunc)(int,char*,...);
int getSomething(void)
{
...
logfunc(LOG_ERROR,"Some message: %s\n",reason);
...
}
-----------------------------------------------------
*** gui.c my C++ code using the library
extern "C" {
int getSomething(void); // prototype of library function
}
// my C++ function which will be called by the library
void guilog(int type,char* format,...); // need __attribute__ ((cdecl)) ??
int main(void)
{
logfunc = guilog;
...
val = getSomething();
...
}
void guilog(int type,char* format,...)
{
... // print error message in GUI window
}
In a C library compiled with gcc there is a pointer to a function defined
and called from within the library. Now I'm using that library in a C++
project and I'd like to set this function pointer to a C++ function. Do I
have to set the C++ function __attribute__((cdecl)) ? Are there any other
things I have to worry about? See example code below.
Thanks very much,
Klaus
Example Code:
-----------------------------------------------------
*** lib.c (compiled with gcc and linked to a library):
void (* logfunc)(int,char*,...);
int getSomething(void)
{
...
logfunc(LOG_ERROR,"Some message: %s\n",reason);
...
}
-----------------------------------------------------
*** gui.c my C++ code using the library
extern "C" {
int getSomething(void); // prototype of library function
}
// my C++ function which will be called by the library
void guilog(int type,char* format,...); // need __attribute__ ((cdecl)) ??
int main(void)
{
logfunc = guilog;
...
val = getSomething();
...
}
void guilog(int type,char* format,...)
{
... // print error message in GUI window
}