Vai al contenuto

Macros

GF_ProjectVX code implements macros in the same way a C programming language pre-processor does.Macros can be defined using the following syntax:MACRO PAR_MACROEND_PAREND_MACRONote that the parameter list may eventually be empty, thus distinguishing between object-like macros, which do not take parameters, and function-like macros, which do takeparameters.A concrete example of macro definition is the following, which takes two bytes and composes a 16-bit word:MACRO MAKEWORDPAR_MACROlobyte;hibyte;END_PAR{ CODE:ST }lobyte + SHL( TO_UINT( hibyte ), 8 )END_MACROWhenever the macro name appears in the source code, it is replaced (along with the actual parameter list, in case of function-like macros) with the macro body. For example, given the definition of the macro MAKEWORD and the following Structured Text code fragment:w := MAKEWORD( b1, b2 );the macro pre-processor expands it tow := b1 + SHL( TO_UINT( b2 ), 8 );