Re: Casting pointers to functions of different types
- From: "straywithsmile@xxxxxxxxx" <straywithsmile@xxxxxxxxx>
- Date: 5 Oct 2006 21:19:37 -0700
I never think this can work, you'd better check on your compiler,but I
think 99% chance, you will receive an error message from the compiler.
and if it is C++, you must wrong.
If your compiler is old version, you may test a function with no
parameter, that means, it will not check the parameter, maybe it can
work. Good Luck!
Yevgen Muntyan wrote:
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
.
- References:
- Casting pointers to functions of different types
- From: Yevgen Muntyan
- Casting pointers to functions of different types
- Prev by Date: Re: Casting pointers to functions of different types
- Next by Date: Re: Casting pointers to functions of different types
- Previous by thread: Re: Casting pointers to functions of different types
- Next by thread: Re: Casting pointers to functions of different types
- Index(es):
Relevant Pages
|
|