Is there a way to make the C macros keyword agnostic?

Is there a way to combine keywords in a macro and get C to behave more dynamically, as in:

#define macro(fun,ction,var,iable) function(variable)

I know that such things exist in other languages.

+3
source share
4 answers

You can use ## to concatenate names in macros

fun ## ction ...

+6
source

No. Although there is ##, as Michael says, it is applied (like all preprocessing) before C or C ++ look up keywords, and even using it to generate any preprocessor keyword allows the preprocessor to fail.

, , - , , .

+2

There are some caveats for using it (for example, you need to go through some hoops to combine the results of other macro extensions), but the GCC docs discuss the basic form:

http://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

0
source

Source: https://habr.com/ru/post/1743077/


All Articles