【问题标题】:How to cause macro expansion before concatenation?如何在连接之前引起宏扩展?
【发布时间】:2023-03-28 03:33:01
【问题描述】:
#define JNI_DECLARE( classname, methodname ) \
     classname  ## methodname( JNI* env ) 

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

这扩展为:

void JAVA_CLASS_open( JNI* env ) {}

我如何获得:

void Java_com_example_open( JNI* env ) {}

?

【问题讨论】:

    标签: c c-preprocessor stringification


    【解决方案1】:
    #define JNI_DECLARE_INNER( classname, methodname ) \
         classname  ## _ ## methodname( JNI* env )
    #define JNI_DECLARE( classname, methodname ) \
         JNI_DECLARE_INNER(classname, methodname)
    

    在此处查看更多信息:C Preprocessor, Stringify the result of a macro

    【讨论】:

    • 附带说明,我非常确信 IAR EWARM 6.4 编译器会做错事。我在 IAR EWARM 和 gcc 中运行了相同的代码,gcc 达到了我的预期,而 IAR 没有。
    • hmm.. 你可以在预处理阶段使用 gcc
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多