
On Tue, 2 Dec 2003, Nathan Hurst wrote:
Ian Grant wrote:
The work Mental had been doing assumed C. Also I suspect serious consideration would be given to keeping it in C if that would make it easier to reuse in other apps. But we really haven't talked about it.
I favour C. Does providing a C interface compromise any C++ class wrapper for that interface? Whilst I have heard of many C++ class interfaces wrapping C libraries I have never heard of the converse. Is it totally impossible because of C++ method names?
It would mean that using classes(structs with methods) for things like NRPoint would be out, which would be a big loss in my book - there is a lot of complex code which is remarkably simplified (and made correct) if reimplemented using vector operations.
Is it actually hard to make a C wrapper around a C++ library? I know that Qoca (a C++ library I use) has a C wrapper around its C++ innards. I suspect that it is to some extent just folk law that it is easier to wrap C in C++ than vice versa.
Well, I've had to make C wrappers around C++ code in the past (in order to link to/from FORTRAN and to plugin C++ analysis code into Excel). It certainly isn't impossible but it can be a bit of a hassle, and it requires some careful planning in laying out the API since you can't use classes, templates, etc. Sometimes if your API is going to be complex it can make more sense to do the core in C with a C++ wrapper, rather than vice versa. So, I'd guess this is why the common wisdom is to make C and wrap with C++. As far as actual linkage though, that's not impossible, just takes some crafting.
Now, I was doing that on Windows with MSVC, and things may be much different nowadays on Linux, so take that with a grain of salt.
Bryce