How to cause macro expansion before concatenation?
Asked Answered
M

1

13
#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 ) {}

?

Mcripley answered 12/8, 2011 at 19:29 Comment(0)
T
15
#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

Trigg answered 12/8, 2011 at 19:33 Comment(2)
As a side note, I pretty confident that the IAR EWARM 6.4 compiler does the wrong thing. I ran this same code in IAR EWARM and gcc, and gcc did what I expected and IAR didn't.Arrowroot
hmm.. you can use gcc for the preprocessor phaseTrigg

© 2022 - 2024 — McMap. All rights reserved.