Revision [14863]

This is an old revision of KeyPgPpmacro made by DkLwikki on 2010-10-12 08:37:36.



Preprocessor directive to define a multiline macro

#macro macro_name( [ parameters ] )
macro body

#macro macro_name( [ parameters, ] variadic_parameterKeyPgDots ... )
macro body

#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 KeyPgDots ... (an ellipsis) behind the last parameter of a macro allows to create a variadic macro, see KeyPgPpdefine #define.
The KeyPgPpifdef #ifdef and KeyPgPpifndef #ifndef preprocessor conditionals can test if macro_name exists or does not exist.
The KeyPgPpundef #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.

'' macro as an expression value
#macro Print1( a, b )
  a + b

Print Print1( "Hello", "World" )

'' Output :
'' Hello World!

'' macro as multiple statements
#macro Print2( a, b )
  Print a;
  Print " ";
  Print b;
  Print "!"

Print2( "Hello", "World" )

'' Output :
'' Hello World!

Differences from QB:
See also:
Back to Preprocessor
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode