Connecting Tech Pros Worldwide Help | Site Map

C/C++

Sean M. Tucker
Guest
 
Posts: n/a
#1: Jul 22 '05
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




Phlip
Guest
 
Posts: n/a
#2: Jul 22 '05

re: C/C++


Sean M. Tucker wrote:
[color=blue]
> I have a project to work on that was done in ANSI C... but I have some[/color]
code[color=blue]
> 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)[/color]

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.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces




johnny@n0sq.net
Guest
 
Posts: n/a
#3: Jul 22 '05

re: C/C++


A C++ compiler/linker will compile/link both C and C++ code.

Sean M. Tucker wrote:
[color=blue]
> 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[/color]

JKop
Guest
 
Posts: n/a
#4: Jul 22 '05

re: C/C++


Sean M. Tucker posted:
[color=blue]
> Hi,
> I have a project to work on that was done in ANSI C...[/color]
but I have some[color=blue]
> code done in C++ that I can use. How can I use the C++[/color]
code in the C[color=blue]
> project?
>
> (I'm using Visual Studio 6, but I wouldn't think it would[/color]
matter if I[color=blue]
> was using g++ or whatever)
>
> Thanks.
>
> -0x53 0x20 0x65 0x20 0x61 0x20 0x6E
>
>
>
>[/color]

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
Closed Thread