1
#define GC_APP_NAME_LIT myapp #define GC_APP_DOMAIN_LIT mydomain #define GC_NATIVE_FUNCTION_DEF(name,args) GC_NATIVE_FUNCTION_DEF_FINAL(GC_APP_DOMAIN_LIT,GC_APP_NAME_LIT,name,args) #define GC_NATIVE_FUNCTION_DEF_FINAL(domain,game,name,args) Java_com_##domain_##game_Game_##name args void GC_NATIVE_FUNCTION_DEF(nativeFunc, (JNIEnv * env, jobject obj)) { ... } 

Using the above code, I am assuming that a function with the following signature will be created.

void Java_com_mydomain_myapp_Game_nativeFunc(JNIEnv * env, jobject obj)) { ... } 

But this does not appear to be working.

On the other hand, A simpler version of this setup works perfectly.

#define GC_NATIVE_FUNCTION_DEF(name,args) Java_com_mydomain_myapp_Game_##name args void GC_NATIVE_FUNCTION_DEF(nativeFunc, (JNIEnv * env, jobject obj)) { ... } 

. . . and creates the function signature as desired.

Need help with identifying what am I doing wrong here. . .

2 Answers 2

3

test.h

#define GC_APP_NAME_LIT myapp #define GC_APP_DOMAIN_LIT mydomain #define CONCAT(a,b,c,d,e,f) a ## b ## c ## d ## e ## f #define GC_NATIVE_FUNCTION_DEF(name,args) GC_NATIVE_FUNCTION_DEF_FINAL(GC_APP_DOMAIN_LIT,GC_APP_NAME_LIT,name,args) #define GC_NATIVE_FUNCTION_DEF_FINAL(domain,game,name,args) CONCAT(Java_com_, domain, _, game, _Game_, name) args void GC_NATIVE_FUNCTION_DEF(nativeFunc, (JNIEnv * env, jobject obj)) { ... } 

Let's pass it through the preprocessor.. gcc -E test.h:

# 1 "test.h" # 1 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "test.h" void Java_com_mydomain_myapp_Game_nativeFunc (JNIEnv * env, jobject obj) { ... } 
Sign up to request clarification or add additional context in comments.

1 Comment

interesting reading to explain this behavior : argument prescan
0

I believe #defines are processed in order. Try moving GC_NATIVE_FUNCTION_DEF_FINAL before GC_NATIVE_FUNCTION_DEF.

1 Comment

Still No good. I believe there is something fundamentally wrong with using ## within the macro like I have done.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.