[comp.lang.c++] Using C++ lib with regular C code?

ewiles@netxdev.DHL.COM (Edwin Wiles) (11/11/89)

	[ PLEASE! Send your mail to the following address. Mail to ]
	[ the 'news' machine (the machine this was posted from) is ]
	[ very unreliable!					   ]
	[		...!hadron!netex!elw			   ]

I have been tasked to write a library of functions for a set of existing
software.  I'd really like to use C++, but cannot (for various reasons)
make massive changes to the existing software.

So, my question is, how much trouble would it be to use a library written
in C++ with code that is written in plain old C?

The library must support multiple flavors of IPC (Inter Process Communications)
in a way that is as transparent as possible to the program using it.  In such a
way that only minor changes are required of existing software to use it.  I can
replace the open, read, and write calls -- and add 'init' calls to the startup
routines -- but I cannot completely rewrite the routines that use them.

How about it?  Am I just asking for a wet carp in the face?  Or is this fairly
easy to do?

					Thanks!
"Who?... Me?... WHAT opinions?!?"		| Edwin Wiles
Schedule: (n.) An ever changing nightmare.	| NetExpress Comm., Inc.
..!uunet!netxcom!ewiles (I'm certain!)		| 1953 Gallows Rd. Suite 300
OR ewiles@iad-nxe.global-mis.DHL.COM (I think!)	| Vienna, VA 22182

bright@Data-IO.COM (Walter Bright) (11/14/89)

In article <1644@netxcom.DHL.COM> ewiles@netxdev.DHL.COM (Edwin Wiles) writes:
<So, my question is, how much trouble would it be to use a library written
<in C++ with code that is written in plain old C?

Construct C "wrapper" functions around your C++ code, and then document
the interface as the C interface, as in:

extern "C" int func(int a)
{
	return cppfunc(a);
}

C and C++ functions may (and do in ZTC++) use different function calling
sequences. It's not good enough to directly call the 'mangled' function
name from a C file.

jkl@csli.Stanford.EDU (John Kallen) (11/15/89)

In article <2204@dataio.Data-IO.COM> bright@dataio.Data-IO.COM (Walter Bright) writes:
!
!Construct C "wrapper" functions around your C++ code, and then document
!the interface as the C interface, as in:
!
!extern "C" int func(int a)
!{
!	return cppfunc(a);
!}

I just got ZTC v 2.0 and discovered I had to use the above construct
for most all my previously written code in C: type-safe linking forces me to.
My question is, (and apologies if this has been discussed before), 
is this: is this construct a standard? If so, where is it defined?

John.
_______________________________________________________________________________
 | |   |   |    |\ | |   /|\ | John K{llen       
 | |\ \|/ \|  * |/ | |/|  |  | PoBox 11215           : HI ." Hello world" ;
 | |\ /|\  |\ * |\ |   |  |  | Stanford CA 94309     
_|_|___|___|____|_\|___|__|__|_jkl@csli.stanford.edu___________________________

bright@Data-IO.COM (Walter Bright) (11/16/89)

In article <11028@csli.Stanford.EDU> jkl@csli.stanford.edu (John Kallen) writes:
<In article <2204@dataio.Data-IO.COM> bright@dataio.Data-IO.COM (Walter Bright) writes:
<!extern "C" int func(int a)
<!{	return cppfunc(a);
<!}
<is this construct a standard?
Yes.

<If so, where is it defined?
In AT&T's 2.0 reference manual. There's also a description in the Zortech
manual.