Macros, Mikroc – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 134

Advertising
background image

Line Continuation with Backslash

If you need to break directive into multiple lines, you can do it by ending the line
with a backslash (

\

):

#define MACRO This directive continues to \

the following line.

Macros

Macros provide a mechanism for token replacement, prior to compilation, with or
without a set of formal, function-like parameters.

Defining Macros and Macro Expansions

The

#define

directive defines a macro:

#define

macro_identifier <token_sequence>

Each occurrence of

macro_identifier

in the source code following this control

line will be replaced in the original position with the possibly empty

token_sequence

(there are some exceptions, which are noted later). Such

replacements are known as macro expansions. The

token_sequence

is some-

times called body of the macro. An empty token sequence results in the removal of
each affected macro identifier from the source code.

No semicolon (

;

) is needed to terminate a preprocessor directive. Any character

found in the token sequence, including semicolons, will appear in the macro
expansion. The

token_sequence

terminates at the first non-backslashed new

line encountered. Any sequence of whitespace, including comments in the token
sequence, is replaced with a single-space character.

After each individual macro expansion, a further scan is made of the newly
expanded text. This allows for the possibility of nested macros: The expanded text
can contain macro identifiers that are subject to replacement. However, if the
macro expands into what looks like a preprocessing directive, such a directive will
not be recognized by the preprocessor. Any occurrences of the macro identifier
found within literal strings, character constants, or comments in the source code
are not expanded

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

126

MikroElektronika: Development tools - Books - Compilers

page

Advertising
This manual is related to the following products: