Re: Casting function pointers
- From: David Brown <david@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 12:21:32 +0100
KKL wrote:
I wonder how casting with function pointers work, how it "should be"<snip>
handled and how it "should not be" handled. Can anyone tell whether
the below code should work or not?
My question is whether these kind of casting for function pointers is
valid. If valid should it work with a predictable behavior or the
behavior is undefined.
It's also important to note that function pointers are not directly compatible with data pointers - you can't necessarily convert a function pointer to a void* and back again, and expect a valid result (although it should work in practice, at least on 32-bit processors). You can't ever convert a method pointer to a function pointer (unless it's a static method).
Personally, I think phrases such as "(void ()(void)* ) funcPtr" are ugly and hard to read. Use typedefs - they make your code clearer, minimise mistakes, and make it easier to change later:
typedef void (*FVoid)(void);
int taskCreate(char* taskName, FVoid funcPtr, ....)
.
- Follow-Ups:
- Re: Casting function pointers
- From: Wilco Dijkstra
- Re: Casting function pointers
- References:
- Casting function pointers
- From: KKL
- Casting function pointers
- Prev by Date: Re: Casting function pointers
- Next by Date: Re: Embeded System Recomendation
- Previous by thread: Re: Casting function pointers
- Next by thread: Re: Casting function pointers
- Index(es):
Relevant Pages
|