delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/20/10:29:26

From: Hans-Bernhard Broeker <broeker AT acp3bf DOT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: libraries headaches
Date: 20 Jan 2000 13:11:20 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 40
Message-ID: <8671ho$co6$1@nets3.rz.RWTH-Aachen.DE>
References: <388637B2 DOT 333A30C6 AT connection DOT com>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 948373880 13062 137.226.32.75 (20 Jan 2000 13:11:20 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 20 Jan 2000 13:11:20 GMT
User-Agent: tin/1.4-19991113 ("No Labels") (UNIX) (Linux/2.0.0 (i586))
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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.

> 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 */
	}

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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019