FPP 1L "17 May 2001" "" "Version 3.0.0" [section 7 of 17]

.-3[OPTIONS]         .-2[LANGUAGE OVERVIEW]         .-1[DEFINITION STATEMENTS]
Top
.+1[EXPRESSIONS]     .+2[MACRO EXPANSION]         .+3[MESSAGE OUTPUT STATEMENTS]


CONDITIONAL STATEMENTS

The conditional statements supported are:

C#if   constant-expression
C#ifdef   name
C#ifndef   name
C#elseif   constant-expression
C#elif   constant-expression
C#else   [optional comment]
C#endif   [optional comment]

Each C#ifxxx statement must have a matching C#endif following it. The two may be separated by any number of C#elseif statements, which may be followed by a single C#else statement.

A branch of a conditional is selected when the expression evaluates to a non-zero value; see the EXPRESSIONS section below for details.

Code between these statements is preserved, but in the unselected branches of a conditional statement, a non-comment statement will be altered to a comment by prefixing it with an initial C##, (or !## in free form) shifting the statement right by three columns. In the selected branch, any initial C## in columns 1 through 3 is stripped; lines without this prefix are copied verbatim.

Because of Fortran line-length limitations (72 in fixed form, 132 in free form), this means that inside an fpp conditional, code lines may not exceed three characters less than the maximum length.

For example, the input


C#if _OS_UNIX
C##C     UNIX code
C##      CALL GETENV(...)
C#elseif _OS_VAXVMS
C     VMS code
      	CALL LIB$TRNLNM(...)
C#endif

when _OS_UNIX=1 produces

C#if _OS_UNIX
C     	UNIX code
      	CALL GETENV(...)
C#elseif _OS_VAXVMS
C##C     VMS code
C##      CALL LIB$TRNLNM(...)
C#endif

When neither _OS_UNIX nor _OS_VAXVMS are defined, the output is

C#if _OS_UNIX
C##C     UNIX code
C##      	CALL GETENV(...)
C#elseif _OS_VAXVMS
C##C     VMS code
C##      CALL LIB$TRNLNM(...)
C#endif

When only _OS_VAXVMS is defined, the original input is sent to the output. If by chance both _OS_VAXVMS and _OS_UNIX were defined, only the UNIX code would be selected, because only the first branch of the conditional would be executed.

Preprocessor conditionals may be nested:

C # if _OS_UNIX
C   # if _SUN
C      # if _SUN4
C      # elseif _SUN3
C      # elseif _SUN386
C      # endif
C   # endif
C # elseif _OS_VMS
C # endif

Any text following #else or #endif is ignored; it can be used to document the conditional, usually with the test from the preceding #if:

C # if _OS_UNIX
C # else NOT _OS_UNIX
C # endif _OS_UNIX
While such trailing text is not permitted by the ISO Standard C/C++ preprocessor, many implementations of the preprocessor silently ignore such text.

fpp directives are not executed if they are in a branch of a conditional that is not currently selected. However, conditional statements are processed to keep track of the current nesting.

On UNIX, the -Dname option for diff(1) can be used to get output from the comparison of two files that is almost correct input for fpp. A simple command pipe diff -Dxxx file1 file2 | sed -e 's/^#/C#/' >file3 will produce an output file file3 from which fpp -Dxxx file3 will recover file2 and fpp -Uxxx file3 will recover file1.


.-3[OPTIONS]         .-2[LANGUAGE OVERVIEW]         .-1[DEFINITION STATEMENTS]
Top
.+1[EXPRESSIONS]     .+2[MACRO EXPANSION]         .+3[MESSAGE OUTPUT STATEMENTS]