I'm working on some library header file that is supposed to be used from both C and C++. Since C does not have a namespace concept I would add a "library prefix" to all names defined in the header file. By contrast, for C++ I would define a namespace. So I currently think of the design as something like this:
mylib.h
#ifdef __cplusplus
namespace mylib{
#define NAME_PREFIX(identifier) identifier
extern "C" {
#else
#define NAME_PREFIX(identifier) mylib_identifier
#endif
int NAME_PREFIX(foo)(void);
//other declarations go here
#ifdef __cplusplus
} //extern "C"
} //namespace mylib
#endif
I have never seen something like that so I am not sure if that is common. Is it discouraged to do so? What are possible drawbacks?