use*_*392 5 c++ gcc g++ backslash
这段代码可以正常使用g ++运行.我不是没有原因.它应该给出一个错误.
#include <iostream>
using namespace std;
int main(){
int x=9;
int y=6;
//note that there is extra backslash in the end of if statement
if(x==y)\
{
cout<<"x=y"<<endl;
}
//note that there is extra backslash in the end of if statement
if(x!=y)\
{
cout<<"x!=y"<<endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
oua*_*uah 19
从C++标准:
(C++ 11,2.2p1)"删除一个反斜杠字符(\)后面紧跟一个新行字符的每个实例,拼接物理源代码行以形成逻辑源代码行.只有任何物理源代码行的最后一个反斜杠才能有资格成为这种拼接的一部分."
C完全相同:
(C11,5.1.1.2翻译阶段p1)"删除紧跟一个新行字符的反斜杠字符(\)的每个实例,拼接物理源行以形成逻辑源行."
所以:
if(x==y)\
{
cout<<"x=y"<<endl;
}
Run Code Online (Sandbox Code Playgroud)
实际上相当于:
if(x==y){
cout<<"x=y"<<endl;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
313 次 |
| 最近记录: |