If word on the street is to be believed, C and C++ can coexist peacefully. Just include the C library< 's header into your C++ file, put them both in a project as seen on the left, and you are set to go.
Unfortunately, this isn't the case - things like polymorphism and other properties of C++ lead to loads of "Undefined reference" errors when trying to access C functions from C++ code and vice versa.
The solution consist of special extern directives - the two sites below should keep you covered:
Mixing C and C++ code in the same program
How to mix C and C++
Good luck porting!
Related posts:
Under normal circumstances there should be no trouble mixing C and C++ code (in my experience, at least). It simply takes a little common sense to predict what may cause a problem (one of the small, but still significant, syntax changes between the languages for instance) to avoid it. My code is C++ with fairly significant C code mixed in and I’ve never had the sort of problem you speak of
Hi med,
thank you so much for talking back!
The problem I had was that I got a large lump of C code which I had to integrate – the code was not written by me…
All the best
Tam Hanna
I think the first few times I saw linker errors due to C++ mangling I was very confused but once you’ve seen it a few times and you know there’s C mixed with your C++ you tend to remember pretty quickly.
Hi Lincoln,
I’ll definitely remember it now – thats why I posted it in the first place
All the best
Tam Hanna