19

在像这样的宏声明中:

#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 ;\
                                     }}\

这些反斜杠 ( \) 是什么意思或在那里做什么?

4

4 回答 4

17

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

于 2013-11-04T10:23:47.270 回答
14

斜杠用于使以下行尾成为预处理器的非换行符。对于预处理器, A#define必须恰好是一行。为了提高可读性,您可以在行尾之前使用反斜杠。预处理器将首先删除任何以反斜杠开头的换行符,并且仅在解析#define. 因此,当您看到多行时,PP 只看到一条。

于 2013-11-04T10:27:03.810 回答
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;
于 2013-11-04T10:23:59.760 回答
4

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

于 2013-11-04T10:23:27.913 回答