wiki:PreprocessorDirectives

Version 2 (modified by wuwenhao, 7 years ago) ( diff )

--

Supported Preprocessor Directives

Back:FortranOverview

Supported preprocessor directive list

  • #include : Header file inclusion
  • #define : Macro expansion
  • #error : Preprocessor error report
  • #ifdef : Conditional compilation based on macro with definitions
  • #ifndef : Conditional compilation based on macro without definitions
  • #if : Conditional compilation based on conditional expressions
  • #elif : Conditional compilation based on conditional expressions
  • #else : Conditional compilation based on conditional expressions
  • #endif : End mark of conditional compilation area.

A FORTRAN example

  • File1: macros.h
    #ifdef ERR
    #error 'ERR is defined.'
    #endif
    #define MSG_HW "Hello World!"
    #define MSG_HI "Hi, "
    #define MSG_BW "Bye World!"
    #define MSG_NM ".."
    #ifndef NAME
    #define NAME "FORTRAN"
    #endif
    
  • File2: preproc.f
    #include "macros.h"
    
    C      A Fortran program example used for testing that
    C      ABC shall correctly handle C preprocessor directives
    C      defined in Fortran source code.
    C      Directives are used mainly for two purposes:
    C        1. User-specified conditional compilation
    C        2. Macro expansion / String substitution
    C      Directives tested here are: 
    C        "include", "define", "undef", "if", "ifdef", "ifndef"
    C        "error"
    
           program HelloWorld
    #if NUM_MSG==1
              print *, MSG_HW
    #elif NUM_MSG==2
              print *, MSG_HW
              print *, MSG_HI, NAME
    #elif NUM_MSG>=3
              print *, MSG_HW
              print *, MSG_HI, NAME
    #ifdef BYE
              print *, MSG_BW
    #undef BYE
    #endif
    #ifdef BYE
    #error "BYE should be undefined." 
    #endif
    #else
              print *, MSG_NM
    #endif
           end
    
    
Note: See TracWiki for help on using the wiki.