I'm using a 3rd party library whose header I'm trying to make compatible under xC. I've hit a snag I need help help with.
The 3rd party library's headers make heavy use of function pointers inside structs. My xC files will not compile with these headers included. I'm trying to modify certain definitions so that these headers will compile whether in c or xC. Take for example the following:
Code: Select all
typedef void(*mycallback_t)(void);
struct _s{
int a;
int b;
mycallback_t c;
int d;
};
Code: Select all
#ifndef __XC__
typedef void(*mycallback_t)(void);
#endif
struct _s{
int a;
int b;
#ifndef __XC__
mycallback_t c;
#endif
int d;
};
So then I tried this:
Code: Select all
#ifndef __XC__
typedef void(*mycallback_t)(void);
#endif
struct _s{
int a;
int b;
#ifndef __XC__
mycallback_t c;
#else
void * unsafe c;
#endif
int d;
};
In xC, is it guaranteed that the size of a function pointer is equal to a void pointer?
Note, this is not true with C/C++. In C/C++ there is no guarantee at all on the size of a function pointer. However, I've seen here on this forum many suggestions to other users working with function pointers to use void pointers to hold there function pointers in xC before passing them to a C function which will eventually call the callback. Here are a few posts:
http://www.xcore.com/viewtopic.php?f=26&t=5739&p=29131
http://www.xcore.com/viewtopic.php?f=47&t=4518&p=23144
Thanks!!