Undefining macros, Mikroc – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 137

Advertising
background image

Here is a simple example:

// A simple macro which returns greater of its 2 arguments:

#define _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 of the arguments in
macro body – this will avoid possible problems with operator precedence.

Undefining Macros

You can undefine a macro using the

#undef

directive.

#undef

macro_identifier

Directive

#undef

detaches any previous token sequence from the

macro_iden-

tifier

; the macro definition has been forgotten, and the

macro_identifier

is

undefined. No macro expansion occurs within

#undef

lines.

The state of being defined or undefined is an important property of an identifier,
regardless of the actual definition. The

#ifdef

and

#ifndef

conditional direc-

tives, used to test whether any identifier is currently defined or not, offer a flexible
mechanism for controlling many aspects of a compilation.

After a macro identifier has been undefined, it can be redefined with

#define

,

using the same or a different token sequence.

MikroElektronika: Development tools - Books - Compilers

129

page

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

Advertising
This manual is related to the following products: