Is there a way to concatenate keywords in a macro and get
C to behave in a more dynamic fashion as in:
#define macro(fun,ction,var,iable) function(variable)
I know this kind of thing exists in other languages.
Is there a way to concatenate keywords in a macro and get
C to behave in a more dynamic fashion as in:
#define macro(fun,ction,var,iable) function(variable)
I know this kind of thing exists in other languages.
You can use ## to concatinate names in macros
fun##ction ...
No. Although there is ##
as Michael says, it is applied (as all preprocessing) before C or C++ looks at keywords, and even using it to generate any preprocessing keyword is allowed to crash the preprocessor.
So, as a rule, if something doesn't compile when you input it directly, it won't when generated by the preprocessor either.
There are some caveats to its use (e.g. you've got to jump through some hoops to concatenate the results of other macro expansions), but the GCC docs discuss the basic form: