HP Fortran Programmer's Guide (March 2010)
Compiling and linking
Special-purpose compilations
Chapter 296
before compilation. But debugging lines are nonstandard, available only in fixed-form source,
and not nearly as powerful as the cpp directives. Although cpp directives are not a standard
feature of Fortran, cpp is a de facto standard feature of UNIX systems.
This section discusses how to do the following:
• Invoke cpp from the f90 command line.
•Use the -D option to define cpp macros.
• Save the preprocessed output generated by cpp.
For more information about the cpp command and the directives it supports, see the cpp(1)
man page.
Processing cpp directives
By default, the f90 command passes source files ending in the .F extension to cpp. Compiling
with the +cpp=yes option enables you to override this default and cause the f90 driver to pass
all source files to cpp. If you do not compile with the +cpp=yes option and if the source file
does not have the .F extension, the compiler treats any cpp directives (but not any embedded
Fortran statements) as comments and ignores them. (As a language extension,
HP Fortran allows comments to begin with the # character, which is also the prefix character
for all cpp directives.)
Consider the following program:
Example 2-9 cpp_direct.f90
PROGRAM main
REAL :: x
WRITE (6, FMT=’(A)’, ADVANCE=’NO’) ‘Enter a real number: ‘
READ *, x
#ifdef DEBUG
PRINT *, ‘The value of x in main: ‘, x
#endif
PRINT *, ‘x =’, double_it(x)
END PROGRAM main
REAL FUNCTION double_it(arg)
REAL :: arg
#ifdef DEBUG
PRINT *, ‘The value of x in double_it: ‘, arg
#endif
double_it = 2.0 * arg
END FUNCTION double_it