HP Fortran Programmer's Guide (September 2007)

Compiling and linking
Special-purpose compilations
Chapter 2 91
The program uses the #ifdef and #endif directives around PRINT statements. If the macro
DEBUG is defined, cpp will leave the PRINT statements in the source text that is passed to the
compiler; if it is not defined, cpp will remove the statements. You can define the macro in the
source text, using the #define directive; or you can define it on the command line, using the
-D command-line option. The advantage of the option is that it does not require editing the
source file to define or undefine a macro.
The following command line uses the -D option to define the macro DEBUG (the space between
-D and DEBUG is optional):
$ f90 +cpp=yes -D DEBUG cpp_direct.f90
Here is the output from a sample run of the executable program created by the preceding
command line:
$ a.out
Enter a real number: 3
The value of x in main: 3.0
The value of x in double_it: 3.0
x = 6.0
The next command line does not use the -D option, so that DEBUG is undefined, causing cpp to
remove the PRINT statements from the source text that is passed to the compiler:
$ f90 +cpp=yes cpp_direct.f90
Here is the output from the nondebugging version of the program:
$ a.out
Enter a real number: 3.3
x = 6.6
Saving the cpp output file
By default, the f90 command discards the source text as processed by cpp after compilation.
However, you can preserve this text by compiling with the +cpp_keep option. If the source file
has the .F or .f extension, the output from cpp is written to a file with the same name but
with the .i extension. If the source file extension is .f90, the output file has the .i90
extension.
Here is the previous command line to preprocess and compile cpp_direct.f90, with the
addition of the +cpp_keep option:
$ f90 +cpp_keep +cpp=yes cpp_direct.f90
After the PRINT statements have been removed, the resulting output file looks like this:
$ cat cpp_direct.i90
# 1 "cpp_direct.f90"
PROGRAM main
REAL :: x