Concatenating an expanded macro and a word using the Fortran preprocessor

前端 未结 1 652
不思量自难忘°
不思量自难忘° 2020-12-12 00:33

I\'m trying to concatenate a word in the source code with the expansion of a preprocessor macro. Basically I have foo somewhere in the code, and with a #d

相关标签:
1条回答
  • 2020-12-12 00:56

    I have done some research and it seems that basically most Fortran compilers (i.e. Intel and PGI) use a relatively normal C-preprocessor with a token pasting operator. We only need a special treatment for gfortran, which uses a C preprocessor in traditional mode without a token pasting operator.

    Thanks to an entry on c-faq.com I found this definition of a CAT macro that works with all compilers I tested so far:

    #ifdef __GFORTRAN__
    #define PASTE(a) a
    #define CAT(a,b) PASTE(a)b
    #else
    #define PASTE(a) a ## b
    #define CAT(a,b) PASTE(a,b)
    #endif
    

    Another solution (that still uses the /**/ trick) was posted by Jonathan Leffler in this answer to a related question.

    0 讨论(0)
提交回复
热议问题