Mail Archives: djgpp/1998/10/20/12:22:31
On Tue, 20 Oct 1998, Primro wrote:
> Well, I know I phrased that very badly (reflecting a shaky
> understanding of all this)... but what I was really asking was "where
> are the functions referenced in the header file coming from." That is,
> if I include stdio.h in a C++ file, do the functions I end up adding
> to my program come from the gpp lib, or the gcc lib (libc). I assume
> the gpp lib.
Your assumption is wrong. The C++ libraries don't replace the standard C
functions, they are in addition to them. When you link a C++ program,
gxx instructs the linker to scan the C++ libraries first, then the C
library. (Add -v to the gxx link command line, and you will see this
yourself.) So even if you link a C++ program, functions declared on
stdio.h and other C headers come from the usual libc.a.
> And beneath that question, basically I am wondering if a C program can
> use functions from my C++ lib file, and vice-versa---> or are they
> somehow too different.
C++ functions can (and do) use functions from libc.a, that is why all
prototypes in the C headers are declared inside ``extern "C"'' block,
just like the one you missed.
But C programs cannot easily use C++ library functions since the actual
name of the function visible to the linker is mangled to include some
indication of its argument types (there can be several different C++
functions with the same name but different argument types--that's what
polymorphism is all about).
> Thanks, Eli- your quick response means I might make some progress
> today.
You are welcome.
- Raw text -