Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cause macro expansion before concatenation?

#define JNI_DECLARE( classname, methodname ) \
     classname  ## methodname( JNI* env ) 

#define JAVA_CLASS Java_com_example
void JNI_DECLARE( JAVA_CLASS, open ) {}

This expands to:

void JAVA_CLASS_open( JNI* env ) {}

How do I get:

void Java_com_example_open( JNI* env ) {}

?

like image 427
user48956 Avatar asked Aug 12 '11 19:08

user48956


People also ask

What is concatenation of macro parameters?

Concatenation means joining two strings into one. In the context of macro expansion, concatenation refers to joining two lexical units into one longer one. Specifically, an actual argument to the macro can be concatenated with another actual argument or with fixed text to produce a longer name.

How is macro expanded?

Macro expansion is an integral part of eval and compile . Users can also expand macros at the REPL prompt via the expand REPL command; See Compile Commands. Macros can also be expanded programmatically, via macroexpand , but the details get a bit hairy for two reasons. The second complication involves eval-when .

What is ## in C macro?

The double-number-sign or token-pasting operator (##), which is sometimes called the merging or combining operator, is used in both object-like and function-like macros. It permits separate tokens to be joined into a single token, and therefore, can't be the first or last token in the macro definition.

What does the '#' symbol do in macro expansion?

The number-sign or "stringizing" operator (#) converts macro parameters to string literals without expanding the parameter definition. It's used only with macros that take arguments.


1 Answers

#define JNI_DECLARE_INNER( classname, methodname ) \
     classname  ## _ ## methodname( JNI* env )
#define JNI_DECLARE( classname, methodname ) \
     JNI_DECLARE_INNER(classname, methodname)

see more here: C Preprocessor, Stringify the result of a macro

like image 108
Karoly Horvath Avatar answered Oct 25 '22 12:10

Karoly Horvath