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

fpp help/possible bug?

Izaak_Beekman
New Contributor II
627 Views
The fpp documentation I can find online seems somewhat sparse. Here are the two pages that I have been consulting:

http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/lin/compiler_f/bldaps_for/common/bldaps_use_ffpdir.htm

http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/lin/compiler_f/bldaps_for/common/bldaps_use_fpp.htm

I would like to concatenate fpp variables declared on the command line with static text. I see that in a macro definition, ## is a binary concatenation operator, but so far my experiments have been failing. This should be possible, and is is supported, at least, by Sun as can be seen in Sun's fpp man page. A search for 'fortran fpp' will produce a hit linking to Sun's fpp man page with an example of this.

I have included an example code below. While this example appears highly contrived and there are workarounds for this specific example, my other code is considerably more complicated; I need to be able to concatenate one of more fpp variables declared on the command line with static text.

[fortran]PROGRAM fpptest
  IMPLICIT NONE
  INTEGER, PARAMETER :: R4 = 4, R8 = 8
# ifdef my_numeric_kind
# define my_real_kind(x) R##x
  REAL(my_real_kind(my_numeric_kind)) :: foo
# else
  REAL :: foo
# endif
END PROGRAM fpptest
[/fortran]
Without defining the variable my_numeric_kind on the command line the results are as expected:

[bash]$ fpp -Dmy_numeric_kind=4  fpptest.F90
# 1 "fpptest.F90"
PROGRAM fpptest
  IMPLICIT NONE
  INTEGER, PARAMETER :: R4 = 4, R8 = 8


  REAL(Rmy_numeric_kind) :: foo
# 9

END PROGRAM fpptest
[/bash]
But if I try to concatenate the text 'R' with my_numeric_type this fails, that is the my_real_kind macro is expanded, but the value of my_numeric_kind is not substituted.

[bash]$ fpp -Dmy_numeric_kind=4  fpptest.F90
# 1 "fpptest.F90"
PROGRAM fpptest
  IMPLICIT NONE
  INTEGER, PARAMETER :: R4 = 4, R8 = 8


  REAL(Rmy_numeric_kind) :: foo
# 9

END PROGRAM fpptest
[/bash]
If anybody knows a way to accomplish this concatenation I would love to know how. This does not seem to me to be an unreasonable request from a preprocessor, so there should be a way to do this, or this could be a bug.
0 Kudos
1 Reply
TimP
Honored Contributor III
627 Views
Several organizations avoid these differences among built-in fpp versions e.g. by setting up a Makefile to pre-process by the same tools used by gfortran:
gcc -traditional -E -x c $*.F > $*.f
ifort -c $*.f

This scheme may be easier than using fpp in those compilers which require 2 copies of -D items for fpp.

On a case-insensitive file system, you must arrange that the temporary files are in a separate directory from the .F.
0 Kudos
Reply