Re: Casting function pointers




"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"
handled and how it "should not be" handled. Can anyone tell whether
the below code should work or not?

<snip>
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


.



Relevant Pages

  • Re: [PATCH] x86, ioremap: use %pR in printk
    ... return string(buf, end, sym, field_width, precision, flags); ... %pF output the name of a function pointer ... %pR output the address range in a struct resource ... * function pointers are really function descriptors, ...
    (Linux-Kernel)
  • Re: [PATCH] x86, ioremap: use %pR in printk
    ... return string(buf, end, sym, field_width, precision, flags); ... %pF output the name of a function pointer ... %pR output the address range in a struct resource ... * function pointers are really function descriptors, ...
    (Linux-Kernel)
  • Re: [PATCH] x86, ioremap: use %pR in printk
    ... return symbol_string(buf, end, ptr, field_width, precision, flags); ... %pF output the name of a function pointer ... %pR output the address range in a struct resource ... * function pointers are really function descriptors, ...
    (Linux-Kernel)
  • Re: Function Pointers
    ... > I am trying to get a handle on function pointers, ... This is a pointer to function. ... a member function, you need to declare it a pointer to member. ... > Getting the cryptic error: ...
    (comp.lang.cpp)
  • RE: vs 8 bug ?
    ... request indicates that upon return from the call to "pApuUpdateHWclock" ... the __cdecl is present while in the declaration of ... then create function pointers that look like pointers: ... If you f*** up a function pointer cast you are in trouble. ...
    (microsoft.public.vc.language)