I am parallelizing an existing FORTRAN application. I don't want to directly change parts of its code so I am using preprocessor directives to accomplish my goal. This way I am able to maintain the readability of the code and I won't induce errors in parts of the code that have already been tested. However, when I try to preprocess my source with the GNU C preprocessor I get the following error message (gcc version 4.7.2 (Debian 4.7.2-5)):
test.f:9:0: error: detected recursion whilst expanding macro "ARR""
This simple test program demonstrates my problem:
PROGRAM TEST
IMPLICIT NONE
INTEGER I,OFFSET,ARR(10)
#define ARR(I) ARR(OFFSET+I)
DO I=1,10
ARR(I)=I
END DO
#undef ARR(I)
END PROGRAM TEST
This is the commandline output:
testing$ gfortran -cpp -E test.f
# 1 "test.f"
# 1 "<command-line>"
# 1 "test.f"
PROGRAM TEST
[...]
test.f:9:0: error: detected recursion whilst expanding macro "ARR"
DO I=1,10
ARR(OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+OFFSET+I)=I
END DO
[...]
END PROGRAM TEST
This site provides some information on the preprocessor I am using:
http://tigcc.ticalc.org/doc/cpp.html#SEC10
As it seems I am using a function-like macro with macro arguments.
Why is the preprocessor detecting a recursion? [EDIT] - Maybe because I use the same name for Makro and Identifier?
Why isn't the preprocessor capable of interpreting upper case directives (#DEFINE instead of #define)? - I am asking, because I haven't had this problem with the ifort preprocessor.
BTW: I am able to preprocess the original code either using the ifort preprocessor -fpp, or by changing the source in the following way:
PROGRAM TEST
IMPLICIT NONE
INTEGER I,OFFSET,ARR(10)
#define ARR_T(I) ARR(OFFSET+I)
DO I=1,10
ARR_T(I)=I
END DO
#undef ARR_T(I)
END PROGRAM TEST