Keil Logo

GENERAL: CARRYING A #DEFINE MACRO OVER TO THE NEXT LINE


Information in this article applies to:

  • C166 All Versions
  • C251 All Versions
  • C51 All Versions

QUESTION

I'm analyzing a .C source file made by another programmer that has a #define macro definition longer than 30 lines. At the end of each line I found a backslash return character sequence ( "\" ). What does this sequence mean and how does the environment deal with it?

ANSWER

The backslash character ('\') is the line continuation character. It must be the last character on a line. The preprocessor joins lines ending with a line continuation character into a single line (for purposes of preprocessing and compilation).

When you create a macro that is very long it is easier to read if the macro definition is split into multiple lines. The line continuation character allows this.

For example:

#define  CALC ( a , b ) \ 
( ( a * b ) +  ( a - 2 ) - \ 
( b * 2 ) )

The above example is equivalent to.:

#define  CALC ( a , b )  ( ( a * b ) +  ( a - 2 ) - ( b * 2 ) )

Last Reviewed: Tuesday, June 29, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  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.