On May 13, 6:29 pm, "Chris Thomasson" <cris...@comcast.netwrote:
I was wondering of the foo::m_fp_callback member will really have extern "C"
linkage...
A member function, even a static member, will always have C++
linkage, see §7.5/4: "A C language linkage is ignored for the
names of class members and the member function type of class
member functions."
simple code
____________________________
#include <cstdio>
extern "C" typedef void (fp_callback_c_t) (void*);
struct foo {
void operator()();
static fp_callback_c_t m_fp_callback;
};
void foo::operator()() {
printf("(%p) - foo::operator()\n", (void*)this);
}
extern "C" void foo::m_fp_callback(void *state) {
foo* const _this = reinterpret_cast<foo*>(state);
(*_this)();
}
int main() {
foo f;
f.m_fp_callback(&f);
printf("\n\n____________________\npress <ENTERto exit...\n");
getchar();
return 0;}
--------
I think the answer is no way will it have C linkage...
Although I can't seem to make any compilers complain about
it...
I'm not sure where you expect a complaint in the above. Despite
the `extern "C"' in the program text, there's not the slightest
`extern "C"' in the program itself, so there's nothing for the
compiler to complain about. (Perhaps a warning because of an
`extern "C"' which is ignored?)
Try passing &foo::m_fp_callback to a function which expects a
fp_callback_c_t as argument, and you should get an error. (Sun
CC complains in this case, for example.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34