I have a C header that was written to compile as both C and C++ (it only uses features from the common subset, and uses that extern "C" thing).
Problem is, that header declares stuff in the global namespace. I’d rather avoid that for the usual reasons. I thought about doing this:
namespace foo {
#include <foo.h>
}
Is doing this a good idea? Do I have alternatives that don’t include editing the header file?
No, it’s a bad idea. With C++ declarations, it’s likely to introduce linker errors as identifiers get declared in the wrong namespace. With C declarations, it works, but it may hide clashes between identifiers in the global namespace (which you were trying to avoid, I guess) until link time; it doesn’t really put the identifiers in a namespace.
A better idea would be to put your own identifiers in a namespace and avoid defining anything but
mainin the global one.