Add namespace string to all functions

In C, I want to add a namespace prefix string (without quotes) to all the functions for which I want this to happen, and later it is easy to change the namespace string.

My approach:

#define NAMESPACE project_name

void NAMESPACE_func_name()
{
}

That should become:

void project_name_func_name()
{
}

Is it possible how? Thank you for your help.

+4
source share
2 answers

You can do this using the macro concatenation operator and function macros:

#define NAMESPACE(name) project_name_ ## name

void NAMESPACE(func_name)(void)
{
    ...
}
+7
source

You can do this with the concatenation macro

#define NAMESPACE(function) project_name ## function

void NAMESPACE(func_name)()
{
}
+2
source

All Articles