So I've seen some C libraries written so that they compile without any changes with a C++ compiler, for example Lua.
What are some advantages and disadvantages of doing this?
A few basic ones I see are:
Advantages:
- library can be used with any C or C++ project with no extra effort (without using
extern "C"
for example).
Disadvantages:
- Harder to maintain because you need it compile as both (involves things like extra casts which can hide bugs)
- Either limit yourself to C/C++ (sacrificing things like flexible array members), or end up with non-standard C++.
But I'm sure there's more to consider than just the above advantages and disadvantages. What sort of cases would doing this be appropriate, instead of using either pure C or C++ for the library?