Mikroc – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 135

Advertising
background image

A macro won’t be expanded during its own expansion (so

#define MACRO

MACRO

won’t expand indefinitely).

Let’s have an example:

/* Here are some simple macros: */

#define ERR_MSG "Out of range!"

#define EVERLOOP for( ; ; )

/* which we could use like this: */

main() {

EVERLOOP {

...

if

(error) {Lcd_Out_Cp(ERR_MSG); break;}

...

}

}

Attempting to redefine an already defined macro identifier will result in a warning
unless the new definition is exactly the same token-by-token definition as the
existing one. The preferred strategy where 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.

MikroElektronika: Development tools - Books - Compilers

127

page

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

Advertising
This manual is related to the following products: