Casting pointers to functions of different types
- From: Yevgen Muntyan <muntyan.removethis@xxxxxxxx>
- Date: Fri, 06 Oct 2006 04:08:23 GMT
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
.
- Follow-Ups:
- Re: Casting pointers to functions of different types
- From: Richard Heathfield
- Re: Casting pointers to functions of different types
- From: Yevgen Muntyan
- Re: Casting pointers to functions of different types
- From: straywithsmile@xxxxxxxxx
- Re: Casting pointers to functions of different types
- From: Yevgen Muntyan
- Re: Casting pointers to functions of different types
- Prev by Date: Re: C variable Storage
- Next by Date: Re: Pointers to dead objects
- Previous by thread: Pointers to dead objects
- Next by thread: Re: Casting pointers to functions of different types
- Index(es):
Relevant Pages
|
Loading