Re: How to deal with calling a member function from a static callback
C type function
On Feb 27, 11:52 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
Angus <anguscom...@gmail.com> writes:
I am using a C style function which requires a 'callback'
function to be defined. This callback function is called
whenever the interface requests new data.
Any C++ function that doesn't throw can be called as a C
function.
That's completely wrong. First of all, of course, non-static
member functions can't be called without an object, so they
can't possibly be called as a C function. Secondly, C and C++
functions (or more precisely, functions with C linkage and with
C++ linkage) have different types, so you can't use one where
the other is expected. And since a member function always has
C++ linkage, even if it is static, you can't call it as a C
function either.
In order to call a C++ function as a C function, the C++
function must be a free function or a static member, the
implementations of the two languages must use the same calling
conventions, and the call itself must either be in assembler
code, or you must take advantage of an error in the compiler.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34