O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Function-like Macros

Macros created by the #define directive are named snippets of code. For constants, the name reflects a literal value. On a more complex level, you can also assign actions (executed statements or logical chunks) to a macro, creating a function-like macro:

#define ALERT printf("Danger!")

With this directive, uses of ALERT in your C code will be replaced with that printf() statement.

As always, there is a catch here: C preprocessor directives must be defined on a single line. Once a new line is encountered, the old directive's definition is over. When the information for a directive won't fit on a single line (which is most likely to happen with function-like macros), you can break up the line by inserting a space followed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required