Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C/C++

Reply
Thread Tools

C/C++

 
 
Sean M. Tucker
Guest
Posts: n/a
 
      07-25-2004
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




 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      07-25-2004
Sean M. Tucker wrote:

> 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.

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




 
Reply With Quote
 
 
 
 
johnny@n0sq.net
Guest
Posts: n/a
 
      07-25-2004
A C++ compiler/linker will compile/link both C and C++ code.

Sean M. Tucker wrote:

> 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


 
Reply With Quote
 
JKop
Guest
Posts: n/a
 
      07-25-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments