##
与gfortran
#define CONCAT(x,y) x##y
program main
integer, parameter:: CONCAT(ID,2) = 3
print*,"Hello", ID_2
end program main
编译错误,因为它运行CPP在传统不gfortran工作(任何OS,不只是苹果机)模式。
根据this thread the gfortran mailing list在传统模式中,正确的操作是x/**/y
,所以你必须在不同的编译器之间的区别:
#ifdef __GFORTRAN__
#define CONCAT(x,y) x/**/y
#else
#define CONCAT(x,y) x ## y
#endif
其他(http://c-faq.com/cpp/oldpaste.html)使用这种形式,当宏传递到CONCAT其行为更好(通过Concatenating an expanded macro and a word using the Fortran preprocessor):
#ifdef __GFORTRAN__
#define PASTE(a) a
#define CONCAT(a,b) PASTE(a)b
#else
#define PASTE(a) a ## b
#define CONCAT(a,b) PASTE(a,b)
#endif
间接配方有助于扩大通过宏字符串连之前(这是太后晚期)。
通常的策略是首先将文件传递给预处理器,然后编译预处理文件:http://stackoverflow.com/questions/38953392/can-cpp-preprocessing-statement-in-fortran-be-indented/ 38953582#38953582 – ewcz
gfortran设置了tradcpp(gcc -E -traditional)以避免c99 //注释和Fortran并置之间的冲突。如上所述,典型的选择是明确使用不同的预处理器,例如通过Makefile。 – tim18