mikroC - C Compiler for Microchip PIC microcontrollers
Macros with Parameters
The following syntax is used to define a macro with parameters:
#define macro_identifier ( <arg_list> ) token_sequence
Note there can be no whitespace between the
The optional
unlike the argument list of a C function. Each comma-delimited identifier plays
the role of a formal argument or placeholder.
Such macros are called by writing
macro_identifier ( <actual_arg_list> )
in the subsequent source code. The syntax is identical to that of a function call;
indeed, many standard library C "functions" are implemented as macros.
However, there are some important semantic differences.
The optional
ited token sequences, known as actual arguments, as found in the formal
arg_list
mal argument. An error will be reported if the number of arguments in the two
lists is different.
A macro call results in two sets of replacements. First, the macro identifier and the
parenthesis-enclosed arguments are replaced by the token sequence. Next, any for-
mal arguments occurring in the token sequence are replaced by the corresponding
real arguments appearing in the
tions, rescanning occurs to detect any embedded macro identifiers eligible for
expansion.
page
128
is a sequence of identifiers separated by commas, not
arg_list
must contain the same number of comma-delim-
actual_arg_list
of the
line – there must be an actual argument for each for-
#define
actual_arg_list
MikroElektronika: Development tools - Books - Compilers
and the "
macro_identifier
. As with simple macro defini-
mikroC
making it simple...
".
(
Need help?
Do you have a question about the PIC Microcontrollers PIC12 and is the answer not in the manual?