next up previous
Next: #undef Up: Preprocessor directives Previous: #include

#define

  The #define directive is used to define values for substitution and for #ifdef directives (section gif). Values defined using an #define directive are substituted into the input file when the value found. The syntax for a #define directive is: #define Name Value where Name is a character string, and Value is a character string, integer, or floating point value. The defined value will be substituted into the file where ever Name is encountered. Name can also be used in #ifdef directives. When the command line option -v Name Value is used, values are defined in this way.

If the syntax #define Name is used for the directive, then the Name is defined for use with #ifdef directives only. When the command line option -d Name is used, values are defined in this way. Use of Name outside of an #ifdef directive will result in NAME_DEFINED_WITHOUT_A_VALUE will be substituted in for the Name.

Using the #define directive, the code

/* define_example.inp */
#define ENERGY 100    // define a value
#define ETEMP  10    // define another value
#define EMARGIN 1.1   // define yet another value
#define ECUT ENERGY*EMARGIN    // define a value in terms of other defines
for input e=ENERGY with margin EMARGIN the cut off is ECUT
note the mathematical operations of:
addition:       ETEMP+EMARGIN
subtraction:    ETEMP-EMARGIN
multiplication: ETEMP*EMARGIN
division:       ETEMP/EMARGIN
Note, division is not allowed since it would be confused with the LAHET
end of line character/
#define TEST_VALUE // a value that should exist only for an ifdef
TEST_VALUE was not defined with a value.
expands out to
for input e=100 with margin 1.1 the cut off is 110.000000
note the mathematical operations of:
addition:       11.100000
subtraction:    8.900000
multiplication: 11.000000
division:       10/1.1
Note, division is not allowed since it would be confused with the LAHET
end of line character/
TEST_VALUE_DEFINED_WITHOUT_A_VALUE was not defined with a value.

Unlike the c and C++ preprocessors, the #define directive in this preprocessor cannot be used to define macros.



Jeff Siebers X88554
Mon Apr 21 09:12:07 PDT 1997