Max Bian <[EMAIL PROTECTED]> writes:
> How would I link objects generated (gcc) from C code with object
> generated (g++) from a C++ source?
In general, you can't.
> There isn't any Class stuff in the C++ code. The only thing that
> makes it C++ is some pass-by-reference functions like: SaveIt(int&
> len);
>
> How would I call this type of function from a C source?
A standard ANSI C compiler isn't aware of pass-by-reference
semantics. You would have to have a deep understanding of how the
assembly code calls are generated by the C++ compiler. In addition, C++
name mangling is unknown to C, so even if you somehow figured out how to
spoof pass-by-reference using inline assembly, the linker probably won't
be able to find the C++ function.
In general, you can't link C and C++ together. The exception is for
linking C functions into C++ code. In that situation, you declare the C
function as
extern "C" { void funcname(); }
The extern declaration tells the C++ compiler that the function uses C
linkage. C++ can call a C function, because C++ uses the C function
calling semantics for pass-by-value functions.
> A more general question is: it appears possible that I compile
> anything in C with the g++ compiler. What kind of difference do I
> expect in the final prc?
Note that this presents the answer to your first question. C code is
also C++ code. If you compile your C function with a C++ compiler, then
the C code will be able to call C++ functions that use
pass-by-reference.
However, at that point, you're committed to using C++ on the entire
project. The .prc will probably be larger; make sure that you compile
with -fno-rtti and -fno-exceptions, as well as link with -lnoexcept and
it probably won't be much larger than if you had written the entire
project in C.
--
Dave Carrigan ([EMAIL PROTECTED]) | Yow! Just imagine you're
UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-DNS | entering a state-of-the-art CAR
Seattle, WA, USA | WASH!!
http://www.rudedog.org/ |
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/