| | 13 | == A FORTRAN example == |
| | 14 | * File1: macros.h |
| | 15 | {{{ |
| | 16 | #ifdef ERR |
| | 17 | #error 'ERR is defined.' |
| | 18 | #endif |
| | 19 | #define MSG_HW "Hello World!" |
| | 20 | #define MSG_HI "Hi, " |
| | 21 | #define MSG_BW "Bye World!" |
| | 22 | #define MSG_NM ".." |
| | 23 | #ifndef NAME |
| | 24 | #define NAME "FORTRAN" |
| | 25 | #endif |
| | 26 | }}} |
| | 27 | |
| | 28 | * File2: preproc.f |
| | 29 | {{{ |
| | 30 | #include "macros.h" |
| | 31 | |
| | 32 | C A Fortran program example used for testing that |
| | 33 | C ABC shall correctly handle C preprocessor directives |
| | 34 | C defined in Fortran source code. |
| | 35 | C Directives are used mainly for two purposes: |
| | 36 | C 1. User-specified conditional compilation |
| | 37 | C 2. Macro expansion / String substitution |
| | 38 | C Directives tested here are: |
| | 39 | C "include", "define", "undef", "if", "ifdef", "ifndef" |
| | 40 | C "error" |
| | 41 | |
| | 42 | program HelloWorld |
| | 43 | #if NUM_MSG==1 |
| | 44 | print *, MSG_HW |
| | 45 | #elif NUM_MSG==2 |
| | 46 | print *, MSG_HW |
| | 47 | print *, MSG_HI, NAME |
| | 48 | #elif NUM_MSG>=3 |
| | 49 | print *, MSG_HW |
| | 50 | print *, MSG_HI, NAME |
| | 51 | #ifdef BYE |
| | 52 | print *, MSG_BW |
| | 53 | #undef BYE |
| | 54 | #endif |
| | 55 | #ifdef BYE |
| | 56 | #error "BYE should be undefined." |
| | 57 | #endif |
| | 58 | #else |
| | 59 | print *, MSG_NM |
| | 60 | #endif |
| | 61 | end |
| | 62 | |
| | 63 | }}} |
| | 64 | |