Keil™, An ARM® Company

Cx51 User's Guide

Simple Macros

A simple macro is merely an abbreviation for a fragment of code. It is often called a manifest constant because it defines a name for a constant value.

Macros must be defined using the #define directive before they can be used. For example:

#define LEN 128

defines a macro named LEN. When LEN is used in your program (or in preprocessor directives) it is replaced with the text 128. So, a C statement like

char buffer[LEN];

is expanded by the preprocessor into

char buffer[128];

and is subsequently compiled by the compiler.

Note

  • Macro definitions must be a single line. You may use the backslash character ('\') followed by a new-line to continue a macro on a subsequent line (refer to Preprocessor Directives for more information).
  • By convention, macro names are uppercase. If you maintain that convention in your applications, it is easy to tell at a glance if an object is a variable, a function, or a macro.