Preprocessor

Richard E Maine Richard.Maine@nasa.gov
Wed May 4 15:16:00 GMT 2005


On May 4, 2005, at 7:59 AM, Ian Rutt wrote:

> I realise that preprocessor directives are not part of the f95 
> standard,
> but most other compilers support them

Odd. My impression was that very few compilers supported them directly 
in the compiler. Such compilers do exist, but I thought they were the 
exception. I've seen quite a few cases where compilers will 
automatically run the preprocessor before compiling, but that's a bit 
different from supporting it in the compiler. Indeed, the differences 
become quite important when you have code that mixes both the standard 
Fortran include, the cpp #include, and other cpp directives; there's a 
thread related to exactly that subject on the comp-fortran-90 mailing 
list right now.

For those compilers that do at least automatically run the 
preprocessor, the details of how to make that happen vary from compiler 
to compiler. It is a fairly commonly asked question on 
comp.lang.fortran. Perhaps the most common (but not universal) 
convention is that a file name suffix in upper case (i.e. file.F90 
instead of file.f90) often triggers the preprocessing run. I thought I 
recalled seeing something like this in gfortran, but I might have 
misrecalled, it not being something I've actually tried.

Do note that exactly the same effect can be achieved, independent of 
particular compiler support, with appropriate makefile entries to run 
cpp followed by the compiler. After all, that's exactly what most 
compilers do - they just make it a little simpler to do than by 
fiddling with makefiles.

-- 
Richard Maine                |  Good judgment comes from experience;
Richard.Maine@nasa.gov       |  experience comes from bad judgment.
                             |        -- Mark Twain



More information about the Fortran mailing list