C++,在多行代码段中注释
C++, comment in a multi-line piece of code
不应该代码:
int Func(int a, // comment
int b, // comment
int c // comment
) ...
等效于:
int Func(int a, // comment int b, // comment int c // comment) ...
为什么它可以正确构建(至少使用 G++(?
到目前为止,在这种情况下,我总是使用/* */
评论。
int Func(int a, // comment
int b, // comment
int c // comment
) ...
转换为
int Func(int a,
int b,
int c
) ...
在翻译的第三阶段。 如果你想在翻译阶段发生之前单行等效,那么你需要使用类似/* */
int Func(int a /*comment 1*/, int b /*comment 2*/, int c /*comment 3*/ ) ...
从标准
5.7 注释
字符//开始评论,评论立即终止 在下一个换行符之前...
因此,在注释被剥离出来后,编译器最终解释的代码如下所示:
int Func(int a,
int b,
int c
) {}
即使是换行符也将保持不变。
注释与代码无关,因此此代码:
int Func(int a, // comment
int b, // comment
int c // comment
) {}
其实等价于这个:
int Func(int a,
int b,
int c
) {}
或者如果你还想要这个:
int Func(int a,int b,int c) {}
单行注释以//
结尾开头,因此将代码与注释放在同一行会将代码转换为注释,并且您的两个代码段并不等效。
有两种注释:
- 以
//
开头的注释在行尾终止 - 以
/*
开头的注释将在下一个*/
终止
最初的 C 规范只知道/* */
样式注释。
//
样式注释是随C++引入的,后来也在 C 标准中引入(虽然不确定是哪一个(。
所以这个:
int Func(int a, // comment
int b, // comment
int c // comment
) ...
相当于这个:
int Func(int a, /* comment */
int b, /* comment */
int c /* comment */
) ...
相当于这个:
int Func(int a, /* comment */ int b, /* comment */ int c /* comment */) ...
相关文章:
- 修改 VS Code 中的默认C++代码段
- 如何从C++代码中检索 QML 的文本字段中的文本?
- 如何知道用于实现标准代码段的确切数据结构和算法,例如在C++STL中?
- C++,在多行代码段中注释
- 有没有一种预处理器的方法可以从调试符号中删除代码段
- 将 find_if() 与数组一起使用的代码段中出错
- 给定代码段中引用的时间和空间位置的所有出现
- 如何在不使用函数或类的情况下重复代码段,以便在C++中实现高性能循环
- gnu内置功能如何在此代码段中使用`___builtin_unreach`工作
- 该代码段在 Colliru 中编译时带有警告,但在 Ideone 中正常编译.哪一个是正确的
- §7.1.6.3/1 (C++14) 不接受下面第二个代码段中的构造。这是为什么呢?
- 为什么在代码段中从 char* 转换为 st::string 比从 const char* 更可取
- 可移植可执行文件是否可以直接绝对引用代码段中的外部库,而不是通过 IAT
- 获取加载到内存中时DLL或EXE的代码段的大小
- 复制构造函数在这个C++代码段中被调用了多少次
- c++模板代码段中出错
- 使用 C++11 标准中的第 8.5.3p4 和 p5 段,我如何证明下面的代码段无法编译?
- 为什么主线程在此C++示例代码段中使用<thread>崩溃?
- 代码段中指针的模糊行为
- VS2010:清单创作错误 c1010097:缺少元素 <dependency> 关键元素:清单代码段中"assemblyIdentity"