Is it safe to convert between voidarg
and chararg
or between voidarg
and fooarg
?:
typedef int (*voidarg)(void *);
typedef int (*chararg)(char *);
typedef int (*fooarg)(foo_t *);
Or between voidret
and charret
or between voidret
and fooret
?:
typedef void *(*voidret)(int);
typedef char *(*charret)(int);
typedef foo_t *(*fooret)(int);
I know this may not be safe in C++ (particularly with an unknown foo_t
type), but is it safe according to any of the C standards or major C compilers?
EDIT:
I forgot to mention an important point. I want to call the functions too, i.e. to be able to do this:
int charfunc(char *s) { /* ... */ }
char str[] = "...";
int somefunction(voidarg f, void *data)
{
return f(data);
}
int main()
{
int i = somefunction(charfunc, str);
}