This is the mail archive of the mailing list for the GNU Fortran project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: detecting gfortran with ifdef

Steven Bosscher wrote:
On Thursday 26 October 2006 23:12, Warren Turkal wrote:
Is there a preprocessor symbol defined when using gfortran that can be used
to conditionally compile code only when using gfortran?

No, there isn't.

Note that gfortran does not have an integrated preprocessor, like
e.g. Cray Fortran does.  The program you call to compile your
programs is the driver program called gfortran.  This driver calls
the compiler (f951), and for some files it calls the preprocessor
before the compiler.

If your Fortran source file has the extensions .F, .fpp, .FPP, .F90,
or .F95, gfortran (the compiler driver) calls the C preprocessor in
traditional (i.e. pre ANSI C) mode.  The driver adds one command
line #define to the command line: -D_LANGUAGE_FORTRAN.

So the closest thing to what you want, probably is _LANGUAGE_FORTRAN.

An alternate option is __GNUC__. This, of course, does not distinguish between things compiled with gfortran and things compiled with gcc or other gcc drivers, but those can be trivially distinguished by what language they're in, so that's probably irrelevant.

This does, however, have the failure mode that it will most likely be defined by any compilation process that uses the GNU C preprocessor. On the other hand, it's unlikely to be defined by any compilers that aren't using the GNU toolchain somehow, so it could be a better option there.

- Brooks

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]