Is there a way to (ab)use the C preprocessor to emulate namespaces in C?
I’m thinking something along these lines:
#define NAMESPACE name_of_ns some_function() { some_other_function(); }
This would get translated to:
name_of_ns_some_function() { name_of_ns_some_other_function(); }
When using namespace prefixes, I normally add macros for the shortened names which can be activated via
#define NAMESPACE_SHORT_NAMESbefore inclusion of the header. A header foobar.h might look like this:If I want to use short names in an including file, I’ll do
I find this a cleaner and more useful solution than using namespace macros as described by Vinko Vrsalovic (in the comments).