Cx51 User's Guide

Macros

Perhaps the most useful aspect of the C preprocessor is the ability to create and use macros. Macros enable you to assign short names to source code blocks. When you use the macro name in your source file, the preprocessor replaces it with the source code block specified in the macro definition.

A macro definition includes the name of the macro, the macro body, and may include macro arguments.

  • Simple Macros require no arguments and are the simplest macros to define.
  • Complex Macros accept one or more arguments and may be used like functions.
  • Macro Operators lists special macro operators that may be used in macro definitions.
  • Predefined Macros lists macros that are defined by the compiler at compile-time.

There are a few caveats of macros that deserve further scrutiny.