Y
Yevgen Muntyan
Hey,
Is the following code valid? It has to cast a function pointer to some
fixed type to allow api for storing and calling that function, but is
such cast legal? Code which stored function pointer in array of unsigned
chars would be valid (I guess), but would be lot uglier than this.
typedef void (*AFunc) (void);
typedef void (*ConcreteFunc) (int);
void some_func (int)
{
}
void marshal (AFunc func, int *args)
{
ConcreteFunc cfunc = func;
cfunc (args[0]);
}
int main (void)
{
int arg = 1;
AFunc func = some_func; // here we cast ConcreteFunc to AFunc
marshal (func, &arg, 1); // and then marshal() casts it back
}
Thanks,
Yevgen
Is the following code valid? It has to cast a function pointer to some
fixed type to allow api for storing and calling that function, but is
such cast legal? Code which stored function pointer in array of unsigned
chars would be valid (I guess), but would be lot uglier than this.
typedef void (*AFunc) (void);
typedef void (*ConcreteFunc) (int);
void some_func (int)
{
}
void marshal (AFunc func, int *args)
{
ConcreteFunc cfunc = func;
cfunc (args[0]);
}
int main (void)
{
int arg = 1;
AFunc func = some_func; // here we cast ConcreteFunc to AFunc
marshal (func, &arg, 1); // and then marshal() casts it back
}
Thanks,
Yevgen