- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I help to develop a Fortran/C/C++ open-source project (open-fvs) that builds on Unix, MinGW and VisualStudio/Intel Fortran tool chains, based on cmake tools. I've been stumped by a recent Fortran preprocessor issue that seems like it should be simple. Equivalent issues in C work across the 3 tool chains. In the Visual Studio-Intel Fortran 12 environment I need to call getpid(), which requires using "USE IFPORT". I would like the same code to be able to work across all environments, and preprocessors would seem to be the way to go. Assuming __GFORTRAN__ is defined in the gfortran situation and not in VS/Intel, something like this klunky example is what I have in mind:
!DEC$ IF DEFINED (__GFORTRAN__)
!DEC$ ELSE
use ifport
!DEC$ ENDIF
The !DEC$ lines are ignored by gfortran, but USE IFPORT obviously isn't. I'd appreciate advice on how to create preprocessor directives that will work across the tool chains.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It doesn't seem imaginative, but I use the /fpp directives which are understood by both gfortran and ifort.
I've had customers who set up to use a separate gcc pre-processing step regardless of which fortran is involved.
gcc -E -traditional -x c (or gfortran -E) to translate .F to .f. On Windows, the preprocessed files must go in a new folder or be named .for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just create a file:
!DEC$ IF(.FALSE.) module ifport end module ifport !DEC$ ENDIF
When you compile it with ifort, you get nothing; compile with others and you get an ifport module you may safely USE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could write your own interface for _getpid, thereby avoid IFPORT in Intel Fortran, and simply ignore the warning you'd get about shadowing an intrinsic in gfortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don't use the !DEC$ directives - as Tim hints, use #ifdef and add /fpp when compiling with Intel Fortran.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page