ARM Technical Support Knowledge Articles

CARRYING A #DEFINE MACRO OVER TO THE NEXT LINE

Applies to: General Topics

Answer


Information in this article applies to:


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 ) )

Article last edited on: 2004-06-29 15:46:27

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential