SPL Macro Preprocessor


SPL includes a C/C++ like preprocessor capable of macro expansion and substitution. Lines beginning with the # symbol indicate a preprocessor directive and may occur anywhere within the SPL source file.


The #include "filename" directive replaces that line with the contents of the file filename. The file is first searched in the directory of the original source code and if not found, in a sequence of standard places.


The commonly used form #include <filename> searches only the standard places. #includes may be nested.


The #define directive defines a macro for substitution. For example,


#define NCELLS 32

if (m > NCELLS) n = 1;


All instances of the text NCELLS are replaced with the text 32, so the above line expands to:


if (m > 32) n = 1;


Macros may also contain arguments. For example, below is an excerpt from the include file series.h:


/* argument and variable value types */


#define REAL_VALUE 2


#define STRING_VALUE 4

#define SERIES_VALUE 5

#define WINDOW_VALUE 6


/* variable type tests */

#define IS_INTEGER(v) (argtype(v)==INTEGER_VALUE)

#define IS_REAL(v) (argtype(v)==REAL_VALUE)

#define IS_COMPLEX(v) (argtype(v)==COMPLEX_VALUE)

#define IS_STRING(v) (argtype(v)==STRING_VALUE)

#define IS_SERIES(v) (argtype(v)==SERIES_VALUE)

#define IS_WINDOW(v) (argtype(v)==WINDOW_VALUE)




The #undef indentifier "undefines" indentifier.


The conditional directive #if constant-expression checks whether constant-expression evaluates to non-zero and if so, processes the lines that follow.


The #ifdef identifier checks if identifier is currently defined and #ifndef identifier checks whether identifier is not defined.


All three forms of the conditionals are followed by an arbitrary number of lines, possibly containing a #else line and finally terminated by a #endif line. If the checked condition is true, then any lines between #else and #endif are ignored. If the checked condition is false, then any lines between the test and an #else, or lacking an #else, the #endif, are ignored. Conditionals may be nested.


The special #if @HELP_IDENTIFIER directive displays the text between the #if @HELP_IDENTIFIER and closing #endif clause when the user executes the help identifier statement.