Preprocessor directive to define a multiline macro
Syntax
#macro macro_name( [ parameters ] )
macro body
#endmacro
#macro macro_name( [ parameters, ] variadic_parameter... )
macro body
#endmacro
Description
#macro defines a function like macro where
macro body may span multiple lines.
Parameters supplied to the function like macro are substituted where they occur in the
macro body. The entire
macro body is substituted where ever
macro_name appears in the source code. The number of parameters supplied to a macro must match the number of parameters in its
#macro definition.
Using
... (an ellipsis) behind the last parameter of a macro allows to create a variadic macro, see
#define.
The
#ifdef and
#ifndef preprocessor conditionals can test if
macro_name exists or does not exist.
The
#undef preprocessor directive will undefine a macro so that it may be redefined with another definition.
Macro substitution can be checked by using the -g -r switches. The compiler doesn't erase the intermediate .asm file where the code actually sent to the compiler can be seen close to its translation into assembler.
Example
'' macro as an expression value
#macro Print1( a, b )
a + b
#endmacro
Print Print1( "Hello", "World" )
'' Output :
'' Hello World!
'' macro as multiple statements
#macro Print2( a, b )
Print a;
Print " ";
Print b;
Print "!"
#endmacro
Print2( "Hello", "World" )
'' Output :
'' Hello World!
Differences from QB
See also