Re: Casting function pointers
- From: "Wilco Dijkstra" <Wilco_dot_Dijkstra@xxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 11:15:19 GMT
"David Brown" <david@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:47a1a698$0$14997$8404b019@xxxxxxxxxxxxxxxxxx
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).
Correct. Both pointer to member and pointer to method typically have
a completely different meaning and representation to normal pointers,
including a different bitpattern to represent the null pointer (the 0 value
is already used for offset 0 or the first virtual function). Since there is
a lot more complexity in C++, different C++ compilers all do something
different (and binary incompatible) - except when adhering to a common
ABI.
C function pointers and data pointers are best not mixed.
Wilco
.
- References:
- Casting function pointers
- From: KKL
- Re: Casting function pointers
- From: David Brown
- Casting function pointers
- Prev by Date: Re: C programming on ARM
- Next by Date: Re: Casting function pointers
- Previous by thread: Re: Casting function pointers
- Next by thread: RTS CTS Problem
- Index(es):
Relevant Pages
|