Datasheet
Attempting to redefine an already defined macro identifier will result in a warning
unless a new definition is exactly the same token-by-token definition as the existing
one. The preferred strategy when definitions might exist in other header files is as
follows:
#ifndef BLOCK_SIZE
#define BLOCK_SIZE 512
#endif
The middle line is bypassed if BLOCK_SIZE is currently defined; if BLOCK_SIZE is not
currently defined, the middle line is invoked to define it.
MACROS WITH PARAMETERS
The following syntax is used to define a macro with parameters:
#define macro_identifier(<arg_list>) <token_sequence>
Note that there can be no whitespace between macro_identifier and “(”. The
optional arg_list is a sequence of identifiers separated by commas, like the argu-
ment list of a C function. Each comma-delimited identifier has 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 actual_arg_list must contain the same number of comma-delimited
token sequences, known as actual arguments, as found in the formal arg_list of the
#define line – there must be an actual argument for each formal argument. An error
will be reported if the number of arguments in two lists is not the same.
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
actual_arg_list. Like with simple macro definitions,
rescanning occurs to detect any embedded macro identifiers eligible for expansion.
Here is a simple example:
221
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5