ISO/IEC JTC1/SC22/WG5 N1139 To: SC22WG5 From: David Epstein and David Levine Subject: Conditional Compilation: The fcc approach Dear SC22WG5, We have been working on Fortran Conditional Compilation (CoCo), and can now offer several approaches. In summary: (1) fcc -- cpp-like and Conditional Compilation only (2) fpp -- cpp-like and full preprocessor (including macro substitution) (3) CCF -- Fortran-like and Conditional Compilation only A proposal for (3), a standard Conditional Compilation Facility (CCF) was sent in 1995 July to SC22WG5 email. Alternative approaches (1) and (2) are described in this note. * * * * * * * (1) fcc - Fortran conditional compilation The "fcc" approach is designed as a Fortran-safe, Conditional-Compilation-only subset of cpp (the ANSI C preprocessor). Fcc is based on cpp: the definition in section 3.8 of the C standard serves as the base definition. An attempt is also made to make fcc Fortran-like, technically turning fcc into a superset of a subset of cpp. The problem of defining a cpp-like/Fortran-like syntax is solved by offering a cpp-mode and a fortran-mode. - The fcc-cpp-mode uses cpp syntax so that existing cpp users need not alter their code. For example, not equals is !=. - The fcc-fortran-mode uses fortran syntax so that those not already using cpp need not learn cpp syntax. For example, not equals is /=. Fortran-mode can be either exclusive of cpp-mode, or inclusive. The latter allows all existing cpp practice, as well as easing the way for [new] Fortran users. It's important to keep in mind that this proposal seeks to make use of existing art and practice. By using cpp, we (the Fortran committees) avoid having to verify correctness of the full underlying design; and those members of the user community already using cpp (or a variant thereof) will not have to change. With the fcc approach we propose avoiding making small "improvements" that will cause unnecessary incompatibilities with existing practice. There is one important area of change, and that is to remove certain small aspects of cpp that make it unusable for some Fortran programs. (These changes are fully compatible for the Fortran user.) Thus, fcc should not consider "//" to be an end-of-line comment. (2) fpp - Fortran "preprocessor" (with substitution) Before proceeding to the precise fcc definition, a possibility of another option needs attention. In addition to providing merely conditional compilation, this option also provides text substitution and macro expansion, much like full- featured cpp. This *preprocessor* definition could either be built on top of fcc or be a Fortran-safe subset of cpp. This option we would like to call fpp. In putting forth this proposal, we do not seek to ignite a debate on the merits (and dangers) of macro-substitution in programming languages. Rather, we observe that the facility is already present in cpp, and may well be currently utilized by some portion of the community. Taking away the feature renders fpp incompatible with the current implementation, which would almost certainly lead to a situation in which the capability would be provided anyway by most vendors. Although the feature is fraught with many theoretical dangers, current users have managed to get on with their work with fairly small inconvenience due to the presence of the macro substitution facility. In summary, we present three approaches: (1) fcc -- cpp-like and CoCo only (2) fpp -- cpp-like and full preprocessor (3) CCF -- Fortran-like and CoCo only A goal of this effort is that whichever of these approaches is chosen, the Fortran world benefits. Regards, David Epstein imagine1 and David Levine HP Languages ==== fcc definition ==================================================== fcc -- cpp-like, Conditional Compilation only Here is an outline of fcc. The underlying definition of fcc is that of the ANSI C "preprocessing directives", as specified by the C Standard. "fcc lines" are those that begin with a "#"; they are not seen by the rest of the language processor and so lie outside the normal definition of the Fortran language. It may be useful to visualize fcc as a "pre- processor", i.e., one that runs through the text prior to the normal Fortran compiler; in this model, fcc's output consists of simply Fortran. Preprocessing is only an implementation strategy, of course, and is not required by fcc. Note: Some topics that require extra discussion include "predefined names", "case-insensitivity", "include", and an optional equals in the "#define" line. Although not mentioned, the intent is that the programmer specifies either fcc- cpp-mode or fcc-fortran-mode, and does not mix them. Source form, tokens, misc. -------------------------- both modes ---------- start-fcc-stmt: the '#' character as in cpp source form: in fcc source form, blanks are significant continuation-lines: none char-strings: use "str" or 'str' case-insensitivity: names are case sensitive as in cpp predefined names: open for discussion. Some ideas are __FORTRAN_90, __FORTRAN, __FORTRAN_95 cpp-mode -------- line-length: unlimited pos of '#': anywhere comments: /* slash-star style comments */ in fcc-lines fortran-mode ------------ line-length: 132 pos of '#': anywhere except pos 6 if in fixed source form comments: use ! bang style comments in fcc-lines IF CONSTRUCT ------------ both modes ---------- #ifdef #ifndef #if fcc-log-expr #elif fcc-log-expr #else #endif Defining and Undefining ----------------------- both modes ---------- #define fcc-name fcc-val #define fcc-name #undef fcc-name cpp-mode only ------------- fcc-name shall not be a name used in the non-fcc lines (left up to the programmer, not the processor) DISCUSSION: Some current implementations require an equals in the #define line. Allowing an optional equals helps these customers. #define fcc-name = fcc-val This would not work for an fpp (the equals would become part of the text substitution.) ENDDISCUSSION Expressions ----------- fortran-mode cpp-mode ------------ -------- .and. & && .or. | || .not. ! .eqv. == .neqv. != ==,/=,>,>=,<,<= ==,!=,>,>=,<,<= +,-,*,/ +,-,*,/ () () Include ------- both modes ---------- #include 'fn' #include fortran-mode only ----------------- include 'fn' where 'fn' is defined by Fortran Note that in fortran-mode, the fortran include line is recognized at fcc-time. -------