Gandalf458
Gandalf458

Reputation: 2269

What does it mean to have a block of c++ code with a backslash after each semicolon?

I have recently seen blocks of C++ code where there is a "\" after each semicolon. It seems very odd to me. Perhaps it is nothing more than a mistake or the remnants of some long forgotten comments (although those have a forward slash "/" ). What impact would this "\" have on the code?

Her is a code sample.

#define PE_DECLARE_CLASS(class_) \
typedef class_ MyClass; \
static void setSuperClasses(); \

Upvotes: 20

Views: 7016

Answers (1)

JoergB
JoergB

Reputation: 4453

A backslash as last character in a line causes this line to be joined with the next for preprocessing. For regular C++ parsing newlines are simply whitespace, so this does not matter. But preprocessor directives, in particular macro definitions end at the end of line.

Using a backslash for line continuation allows formatting long macro bodies across multiple source text lines.

Upvotes: 30

Related Questions