-2

I saw this code:

#define REPEAT(statement) \
{ \
    while((count & ~0x7) && ((x+8) < width)) \
        UNROLL8( statement; count--; x++; ); \
    \
    while((count > 0) && (x < width)) \
    { \
        statement; \
        count--; \
        x++; \
    } \
}

What is the \ for here?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Naor Hadar
  • 537
  • 1
  • 6
  • 19
  • 1
    it means the `#define` is extended to more than one line – Rakib May 25 '14 at 14:28
  • It's a line continuation character. – The Paramagnetic Croissant May 25 '14 at 14:28
  • Please don't answer and upvote this duplicate question which lacks research effort. Please close it as a duplicate instead. – The Paramagnetic Croissant May 25 '14 at 14:29
  • @STLDeveloper Why do you think so? The syntax is well explained there ... – πάντα ῥεῖ May 25 '14 at 14:35
  • 3
    @πάντα ῥεῖ - The OP doesn't know isn't asking how to make a multi-line preprocessor directive. He's seen something that he doesn't understand is asking assistance in identifying it. Those are not the same thing. – STLDev May 25 '14 at 14:37
  • @STLDeveloper It's not the point about the literal question text for marking something as a duplicate, but that there's an appropriate answer for the OP's problems. – πάντα ῥεῖ May 25 '14 at 14:40
  • @πάνταῥεῖ, I disagree. In this case the OP would have to know the answer what he's looking at in order to find that answer. The reason for that is because that question is not the OP's question. BTW, are you often a troll? – STLDev May 25 '14 at 14:44
  • @STLDeveloper You may disagree of course! Until you have enough rep to participate in [close/repoen voting](http://stackoverflow.com/help/privileges), this might turn out to be pretty irrelevant. – πάντα ῥεῖ May 25 '14 at 14:48
  • @πάνταῥεῖ - Now there's something we can agree upon! – STLDev May 25 '14 at 14:50

4 Answers4

4

The definition of a macro only includes a logical single line. The \ at the end of each line of the macro definition is used to allow the macro definition to be split into multiple physical source lines (presumably for readability reasons).

This works because a \ followed by a new-line is deleted during phase two of translation, but the preprocessor is run later, in phase four. [lex.phases]/2:

Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.

Mankarse
  • 39,818
  • 11
  • 97
  • 141
3

In macro definition, \ means continuation.

The definition of a macro should be on ONE line, i.e without any break. Since in your definition, the macro definition is so big that it cannot conveniently accommodate on the same line without destroying the readability. So \ is used to indicate to the preprocessor the definition continues to the next line so that the program's readability is maintained.

Note that \ must be followed by a newline. Make sure that there is no space after \.

Nawaz
  • 353,942
  • 115
  • 666
  • 851
1

those are line continuations necessary to interpret the whole #define thing as one line, as required by the preprocessor syntax. this way it's just more readable.

Pavel
  • 7,436
  • 2
  • 29
  • 42
1

It means that the macro text is continued after the actual line breaks you have.

#define reads its contents from one contigious line. The \ character just 'escapes' (i.e. skips) the following line break.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190