Keil Logo

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.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.