Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

ifort environment variable

Lester
Beginner
2,153 Views

Hi

Is there an environment variable (like __GFORTRAN__ for gfortran) that can be used to as a flag to the preprocessor so that it will preprocess part of the file when it is a fortran file and skip that part when it is a C or C++ file?  It would be valuable if it worked the same for Windows.

 

0 Kudos
6 Replies
Steven_L_Intel1
Employee
2,153 Views

gfortran needs that because it uses cpp for preprocessing Fortran code. Intel Fortran has its own Fortran-specific preprocessor, fpp, which doesn't need such a thing. Can you describe a scenario where such a thing would be useful? 

0 Kudos
mecej4
Honored Contributor III
2,153 Views

I do not understand part of #1: do you really imply that a single source file would contain C/C++ code and Fortran code? What is it that distinguishes the part that you want skipped/not skipped from the rest of the source file?

0 Kudos
Lester
Beginner
2,153 Views

We have an include file that has several defines in it that are useful for both fortran and C preprocessing.  Unfortunately, another include was added to it that is fortran specific, and was bracketed with the if __GFORTRAN__ so it did not get used in the C++ code.  This worked OK on Linux, where the primary compiler used was gfortran, but blows up on Windows, where Intel is the primary compiler, and prevents using Intel on Linux.  I recognize this was not the best way this should have been done, but after the fact, it will be much easier to fix the if than to go through and modify all the all the other routines that are involved.

0 Kudos
Steven_L_Intel1
Employee
2,153 Views

Ah, I see. Perhaps __INTEL_COMPILER could be used for this, though this would also be set if you used Intel C++. Or you could add a -DFORTRAN or some such to your ifort build options.

0 Kudos
TimP
Honored Contributor III
2,153 Views

If you must use gFortran specific preprocessing you can direct output of gfortran -E to a file which Ifort can compile, or you could define the macro symbol for fpp.  If using gfortran to preprocess on windows, input and output must be in separate folders.

0 Kudos
Lester
Beginner
2,153 Views

OK, thanks everyone.  What we have gone to, which seems to work is setting the if test as below.

#if defined(__GFORTRAN__) || (defined(__INTEL_COMPILER) && !(defined(__ICC)||defined(__ICL))) || defined(_G95__)


I'm not sure why G95 got added in, as I don't think it will compile everything, but it doesn't seem to hurt.

0 Kudos
Reply