Hi everyone, (Very Sorry, if this is the wrong group in which I am
posting this query).
Code snippet:
//C library
typedef int (*PFunc)(int* aArg);
void call_c_foo(PFunc aPtrtoFunc)
{
int* theArg;
//Assume theArg pointer is valid hereafter
//Do something...and then...call
PFunc(theArg);
//some more stuff
}
================================
//C++ Code using C library
class CPP
{
public:
static int Ditto(int* aInt);
void InMemberFunction()
{
call_c_foo(Ditto);
}
};
=================================
On URL:
http://www.parashift.com/c++-faq-lit....html#faq-33.2
{
although it probably works on most compilers, it actually would have to
be an extern "C" non-member function to be correct, since "C linkage"
doesn't only cover things like name mangling, but also calling
conventions, which might be different between C and C++.
}
3 QUESTIONS:
1) What does Standard C++ say on this issue? Does the static fucntion
in class CPP is compiled by _most_ of compilers the way it would have
been compiled if it was given extern "C" linkage? In other words, do
_most_ of compilers treat both - static fucntion directive and extern
"C" directive - to be same? Also, why does C++ not allow to declare
linkage of a class to be partly as C and partly as C++? What are the
difficulties in doing this on part of a compiler writer?
2) When I say that a given piece of code (in C++) has "C" linkage, does
it mean that C++ compiler will "supress" its calling conventions as
well when setting up a C call within C++ code while compiling? More
curiously, what all things does a C++ compiler do when it encounters
extern "C" directive while compiling a C++ code?
3) I would have assumed that calling conventions for both extern "C"
linked calls and C++ calls would be same _if_ both the C code (in our
case - the above C library) and C++ code is compiled by _same_
compiler. Is my understanding true?
Thank you very much for the answers in advance,
-Viren