Re: C++ Callbacks



Hi All! :-)

>I think you're confused by the C++ name mangling.

No, they are two completely separate issues.  Name mangling has nothing
to do with calling convention (except of course that functions declared
as "C" are not mangled).  The C++ standard is very specific in
stating that the linkages between C++ and other languages are
implementation defined.

>C++ uses exactly the same calling convention as C (given that both
>compilers come from the >same "manufacturer").  

That is NOT necessarily true.  I am not positive, but I am pretty sure
that KAI C++ uses some different tricks when linking C vs. C++.

>There is no guarantee, but there is also no reason for the gcc
>maintainers to change the calling convention.

Indeed, IF you are willing to state that your program should never
be compiled with anything but g++, you MIGHT be safe.  However, as I
stated in the original message, your code is certainly non-portable.
And it is always possible that standard a specification for C++ linkage
will come to pass in the future, and I am pretty sure that g++ would
glady conform to that, thus even restricting your program to future
versions of g++ is not a guarentee.

>What does the C++ standard have to say about this? 

In section 7.5 of the ISO document (Linkage Specifications) the C++
standard states :

"Two function types with different language linkages are distinct types
even if they are otherwise identical."

Section 7.5.9 goes on to say that this IS implementation dependant.
In addition, as I mentioned, there was a big discussion regarding this
in comp.programming.threads a few months ago.  There was also a smaller
discussion in the C++ newsgroups.  There is simply no guarentee that
C and C++ functions pointers can be used interchangeably.

Best wishes and happy Juel! :-)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]