Disclaimer: I know purists on either side, C or C++, will not like this. The job needs to get done.
I would like to use as many non-OOP related features of C++ to make my C-like coding (but compiled with a C++ compiler, of course) more enjoyable. The end product should be a C-like library (and an accompanying executable) which is relatively easy to embed in C programs.
What I would terribly need is function overloading, for instance. I guess the client code (written in C) could use libffi or similar to get the mangled named, so the functions can be called.
Other nice features would be default values and perhaps templates.
I wouldn’t use any C++ library (only C), no exceptions, no RTTI, and no objects.
- What is the complete list of C++ features which are not in C, which I could use under these restrictions, and what are some common libraries and techniques to make it work as painlessly as possible?
- What should I pay attention to?
I know about the related question, but as I’ve said, I don’t want any glue code (perhaps with the exception of the mangling part, which the client would have to do if he doesn’t use C++), and I wouldn’t use any OOP features. I am ready to make compromises.
I’ll get downvoted a lot for this, because this doesn’t really answer the question, but…
extern "C", and catch all exceptions).If the client is not willing to use C++ (which is perfectly understandable), you’ll have to write glue code anyway. The only solution to minimize glue code is to design a clean API.
It is possible to write the “top layer” (close to the externally visible API) in a way that will require almost no glue, and use C++ for the internals.