Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add namespace string to all functions

Tags:

c

In C, I want to add a namespace prefix string(without quotes) to all functions for which I want it to happen, and later on change the namespace string any time easily.

My approach:

#define NAMESPACE project_name

void NAMESPACE_func_name()
{
}

That should become:

void project_name_func_name()
{
}

Is that possible, how? Thanks for help in advance.

like image 907
Sumit Avatar asked Jan 07 '23 09:01

Sumit


1 Answers

You can do it with the macro concatenation operator and function-like macros:

#define NAMESPACE(name) project_name_ ## name

void NAMESPACE(func_name)(void)
{
    ...
}
like image 62
Some programmer dude Avatar answered Jan 15 '23 05:01

Some programmer dude