Mail Archives: djgpp/2000/01/20/19:49:49
Hans-Bernhard Broeker wrote:
> sam <samirw AT connection DOT com> wrote:
> [...]
> > So who can tell me how to name my functions so that I can write C++ code
> > and libraries.
>
> Your problem, most probably, is not with C++ itself, or the names of
> your functions. It's with *mixing* C and C++ parts (C library, C++
> main program) in the same program.
>
Actually, I had both compiled as C++ but when it didn't work I have changed
the main program to 'C'. Now that I think about it there is no sense to have
libraries in C++ if most of the program is not. Shouldn't even be possible.
>
> > I have stumbled across the term 'name mangling'???
>
> That's exactly your problem, I suspect. C++ adds information to the
> names of objects (variables, functions) to carry type information, for
> things like polymorphism, i.e. a function
>
> int dosomething(double arg1, char *arg2);
>
> may become the following linker-visible symbol:
>
> .globl dosomething__FdPc
>
> C doesn't do that, so the same function would be compiled to
>
> .globl dosomething_
>
> and that's it. To avoid this, you have to *tell* the C++ compiler that
> an external function declaration (prototype in a header) is for a
> C, not a C++ function.
>
> extern "C" {
> /* C declarations here */
> }
>
So that's what that is for.
>
> does that for you. Read up the details in Stroustrup or some other C++
> textbook.
>
> --
> Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
> Even if all the snow were burnt, ashes would remain.
Thank you for your time.
- Raw text -