User manual

mikroC PRO for dsPIC
MikroElektronika
261
A macro call results in two sets of replacements. First, the macro identier and the parenthesis-enclosed arguments
are replaced by the token sequence. Next, any formal arguments occurring in the token sequence are replaced by the
corresponding real arguments appearing in actual_arg_list. Like with simple macro denitions, rescanning occurs
to detect any embedded macro identiers eligible for expansion.
Here is a simple example:
/* A simple macro which returns greater of its 2 arguments: */
#dene _MAX(A, B) ((A) > (B)) ? (A) : (B)
/* Let’s call it: */
x = _MAX(a + b, c + d);
/* Preprocessor will transform the previous line into:
x = ((a + b) > (c + d)) ? (a + b) : (c + d) */
It is highly recommended to put parentheses around each argument in the macro body in order to avoid possible
problems with operator precedence.
Undening Macros
The #undef directive is used to undene a macro.
#undef macro_identier
The directive #undef detaches any previous token sequence from macro_identier; the macro denition has been
forgotten, and macro_identier is undened. No macro expansion occurs within the #undef lines.
The state of being dened or undened is an important property of an identier, regardless of the actual denition. The
#ifdef and #ifndef conditional directives, used to test whether any identier is currently dened or not, offer a
exible mechanism for controlling many aspects of a compilation.
After a macro identier has been undened, it can be redened with #dene, using the same or different token
sequence.
File Inclusion
The preprocessor directive #include pulls in header les (extension .h) into the source code. Do not rely on
preprocessor to include source les (extension .c) — see Add/Remove Files from Project for more information.
The syntax of the #include directive has two formats:
#include <header_name>
#include “header_name”