preprocessor token "#" doesn't work in gfortran as in gcc, intel-fortran or sun-fortran compiler
Maik Beckmann
beckmann.maik@googlemail.com
Wed Jun 10 15:28:00 GMT 2009
Hello,
Consider this code
{{{
#include <stdio.h>
#define TO_STR(EXPR) # EXPR
int main() {
printf("%s\n", TO_STR(bazz));
return 0;
}
}}}
Running
gcc foo.c && ./a.out
gives
bazz
The fortran version is
{{{
#define TO_STR(EXPR) #EXPR
PROGRAM test
print *,TO_STR(bazz)
END PROGRAM test
}}}
Running
ifort -fpp foo.f90 && ./a.out
or
sunf95 -fpp foo.f90 && ./a.out
gives
bazz
as expected.
But
gfortran -cpp foo.f90
chokes with
{{{
foo.f90:4.10:
print *,#bazz
1
Error: Expected expression in PRINT statement at (1)
}}}
After some tinkering I came up with
{{{
#define TO_STR(EXPR) "EXPR"
PROGRAM test
print *,TO_STR(bazz)
END PROGRAM test
}}}
Running
gfortran -cpp foo.f90 && ./a.out
gives
bazz
Why does gfortran -cpp" behave different than gcc or any other fortran compiler
I have around? Is this by intention or just a bug?
More information about the Fortran
mailing list