Changes between Version 1 and Version 2 of PreprocessorDirectives


Ignore:
Timestamp:
05/21/19 06:29:39 (7 years ago)
Author:
wuwenhao
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PreprocessorDirectives

    v1 v2  
    1111* `#else` : Conditional compilation based on conditional expressions
    1212* `#endif` : End mark of conditional compilation area.
     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
     32C      A Fortran program example used for testing that
     33C      ABC shall correctly handle C preprocessor directives
     34C      defined in Fortran source code.
     35C      Directives are used mainly for two purposes:
     36C        1. User-specified conditional compilation
     37C        2. Macro expansion / String substitution
     38C      Directives tested here are:
     39C        "include", "define", "undef", "if", "ifdef", "ifndef"
     40C        "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