C/C++

S

Sean M. Tucker

Hi,
I have a project to work on that was done in ANSI C... but I have some code
done in C++ that I can use. How can I use the C++ code in the C project?

(I'm using Visual Studio 6, but I wouldn't think it would matter if I was
using g++ or whatever)

Thanks.

-0x53 0x20 0x65 0x20 0x61 0x20 0x6E
 
P

Phlip

Sean said:
I have a project to work on that was done in ANSI C... but I have some code
done in C++ that I can use. How can I use the C++ code in the C project?

(I'm using Visual Studio 6, but I wouldn't think it would matter if I was
using g++ or whatever)

If your C code takes no liberties, compile it as C++. (Any warnings or
errors you see are your fault. C permits many abuses that are not necessary
for good code.)

Under VC++, rename the files to .cpp and add them back to a project.
 
J

JKop

Sean M. Tucker posted:
Hi,
I have a project to work on that was done in ANSI C... but I have some
code done in C++ that I can use. How can I use the C++ code in the C
project?

(I'm using Visual Studio 6, but I wouldn't think it would matter if I
was using g++ or whatever)

Thanks.

-0x53 0x20 0x65 0x20 0x61 0x20 0x6E

It's just a matter of somehow indicating to the compiler
that a.cpp is C++ and that b.cpp is C. Then, in your C++
code, make the function declarations as so:

extern "C" int Blah(int);


As for the C code calling C++ functions... no idea.


-JKop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top