The C preprocessor

Introduction

define

use of #define

#define PI 3.149
x=PI*4;

can define functions using macros can define

#define TIMES_THREE(x) (x * 3)
y=TIMES_THREE(5);

can turn on DEBUG eg

#define DEBUG

or do with compiler eg

GCC -DDEBUG (D then macro name)

why use const over define? handled by compiler not preprocessor. means you can do type checking

include

undef

ifdef

ifdef thing: following prints "a" only if DEBUG is defined

#ifdef DEBUG
printf("a");
#endif