Preprocessor

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Wed May 4 15:12:00 GMT 2005


Ian Rutt wrote:
> I've been trying to use gfortran with code containing preprocessor
> lines. For this sample code:
> 
> -------------------------------------------------------------------
> 
> program test_pp
> 
> #ifdef SINGLE
>   integer,parameter :: rk=4
> #else
>   integer,parameter :: rk=8
> #endif
> 
> end program test_pp
> 
> -------------------------------------------------------------------
> 
> I get this output:
> 
> -------------------------------------------------------------------
> 
> Warning: test_dp.f90:4: Illegal preprocessor directive
> Warning: test_dp.f90:6: Illegal preprocessor directive
> Warning: test_dp.f90:8: Illegal preprocessor directive
>  In file test_dp.f90:7
> 
>   integer,parameter :: rk=8
>                         1
> Error: Symbol 'rk' at (1) already has basic type of INTEGER
> 
> -------------------------------------------------------------------
> 
> If I compile with -E (run preprocessor only), I don't get any errors.
> Should this code compile or not? Have I made some sort of mistake in my
> installation (e.g. environment variables)? 

You should either name your file .F90 or use the -x=f95-cpp-input option.
Otherwise the C preprocessor is not run.  Admittedly, the error message is
misleading.

- Tobi



More information about the Fortran mailing list