Chapter 16

Preprocessor Directives and Macros

Preprocessor is the part of the compiler that processes a C program before its compilation. In this chapter, we’ll discuss how to define and use macros in a C program and then we’ll present preprocessor directives that support the conditional compilation of a C program.

Simple Macros

In previous chapters, we have used the #define directive to define a simple macro, which is a symbolic name associated with a constant value. To define a simple macro, we write

#define macro_name replacement_characters

Typically, most programmers choose capital letters to name a macro in order to distinguish them from program variables. The usual practice is to define all macros with global scope at the top of the ...

Get C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.