What do I need to know when mixing C and C++ code?
Related Blog Items
- How can I call a C function f(int,char,float) from my C++ code?
- Advanced Test in C: The 0x0A Best Questions for C Programmers
- How the keyboard works?
- How to inlcude C header files in C++
- Clipping and Clamping with out 'if condition'
Here are some high points (though some compiler-vendors might not require all these; check with your compiler-vendor’s documentation):
- You must use your C++ compiler when compiling main() (e.g., for static initialization)
- Your C++ compiler should direct the linking process (e.g., so it can get its special libraries)
- Your C and C++ compilers probably need to come from same vendor and have compatible versions (e.g., so they have the same calling conventions)
In addition, you’ll need to read the rest of this section to find out how to make your C functions callable by C++ and/or your C++ functions callable by C.
BTW there is another way to handle this whole thing: compile all your code (even your C-style code) using a C++ compiler. That pretty much eliminates the need to mix C and C++, plus it will cause you to be more careful (and possibly ?hopefully!? discover some bugs) in your C-style code. The down-side is that you’ll need to update your C-style code in certain ways, basically because the C++ compiler is more careful/picky than your C compiler. The point is that the effort required to clean up your C-style code may be less than the effort required to mix C and C++, and as a bonus you get cleaned up C-style code. Obviously you don’t have much of a choice if you’re not able to alter your C-style code (e.g., if it’s from a third-party).
source:USENET
[tags]mixing C & C++[/tags]
Popularity: 5%
You need to log on to convert this article into PDF
Related Blog Items - How can I call a C function f(int,char,float) from my C++ code?
- Advanced Test in C: The 0x0A Best Questions for C Programmers
- How the keyboard works?
- How to inlcude C header files in C++
- Clipping and Clamping with out 'if condition'
Related Blog Items
- How can I call a C function f(int,char,float) from my C++ code?
- Advanced Test in C: The 0x0A Best Questions for C Programmers
- How the keyboard works?
- How to inlcude C header files in C++
- Clipping and Clamping with out 'if condition'
Thanks for posting about this. It’s a great blog!
I wrote a blog on mixing C and C++ that you might be interested in. It talks more about how to preserve the beneficial aspects of C++ while doing it than the details of the syntax.
http://fonp.blogspot.com/2008/03/mixing-c-and-c-code.html
June 28th, 2008 at 9:40 pm