21

In a macro declaration like:

#define WAIT_SPI2_TRANSMISSON_END() {while ((SPI2_SR & SPI_SR_TXCTR_MASK) != 0) {\
                                     if( SPI2_SR & SPI_SR_RFDF_MASK ) {\
                                       (void)SPI2_POPR;\
                                       SPI2_SR |= SPI_SR_RFDF_MASK ;\
                                     }}\

What do these backslashes (\) mean or do there?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
masmic
  • 3,526
  • 11
  • 52
  • 105

4 Answers4

18

It's a line continuation character.

There should be nothing else after it (aside from an end of line character), including white space.

It's particularly useful for macros as it adds clarity.

(Very, very occasionally - especially in old code - you'll see the trigraph sequence ??/ in place of \. These days though it's more of an interviewers' trick question.)

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
15

The slashes are used to make the following end of line a non-linebreak for the preprocessor. A #define has to be exactly one line for the preprocessor. To augment readability you can use the backslashes before the end of lines. The preprocessor will first erase any linebreaks preceded by a backslash and only after that parse the #define. So while you see multiple lines, the PP sees only one.

Arne Mertz
  • 24,171
  • 3
  • 51
  • 90
8

It is so called continued line. It means that your line is continued in line that follows. It is simply sometimes easier to read stuff if written this way.

BTW - continued lines are 'glued' at preprocessor pass.

Read here about step #3: gcc docs

Excerpt:

 /\
 *
 */ # /*
 */ defi\
 ne FO\
 O 10\
 20

is equivalent to:

#define FOO 1020

It is noteworthy to say that continued lines do not have to be used within preprocessor macros. It is perfectly legal top write this:

f\
lo\
at f = 5.0; 

which is the same as:

float f = 5.0;
Artur
  • 7,038
  • 2
  • 25
  • 39
4

This means that the define statement goes over more than one line.

Blacktempel
  • 3,935
  • 3
  • 29
  • 53