在每个分号后都有一个反斜杠的 C++ 代码块是什么意思? [英] What does it mean to have a block of c++ code with a backslash after each semicolon?
问题描述
我最近看到 C++ 代码块,每个分号后面都有一个\".这对我来说似乎很奇怪.也许这只不过是一个错误或一些长期被遗忘的评论的残余(尽管那些有正斜杠 "/" ).这个\"对代码有什么影响?
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?
她是一个代码示例.
#define PE_DECLARE_CLASS(class_) \
typedef class_ MyClass; \
static void setSuperClasses(); \
推荐答案
反斜杠作为一行中的最后一个字符会导致该行与下一行连接以进行预处理.对于常规 C++ 解析换行符只是空白,所以这无关紧要.但是预处理器指令,特别是宏定义在行尾结束.
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.
这篇关于在每个分号后都有一个反斜杠的 C++ 代码块是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!