c++ - gcc 多行注释警告

标签 c++ gcc comments compiler-warnings

我收到警告

warning: multi-line comment [-Wcomment]

由于我的评论看起来像

// strings can start with a \ and also end with a \ 

我了解该错误并已看到有关该主题的其他 SO 消息。

我可以轻松修复警告(通过双引号\s)。

我很好奇的是,我注意确保该行以\结尾。该行以\结尾,然后是一个空格。这是预处理器剥离我的尾随空间并因此引入警告吗?

最佳答案

initial processing 期间预处理器对其输入执行一系列文本转换。

这是文档中的引述(相关部分以粗体显示):

Continued lines are merged into one long line.

A continued line is a line which ends with a backslash, . The backslash is removed and the following line is joined with the current one.

...

The trailing backslash on a continued line is commonly referred to as a backslash-newline.

If there is white space between a backslash and the end of a line, that is still a continued line. However, as this is usually the result of an editing mistake, and many compilers will not accept it as a continued line, GCC will warn you about it.

在这种情况下,最好使用 '\' 而不是 \ 因为反斜杠用作符号而不是续行指示符。另一个(主观上较差的)选项是在 \ 之后放置一个结束的非空白字符(例如一个点)。

关于c++ - gcc 多行注释警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46771175/

相关文章:

C++子类访问主类变量

c++ - Eclipse CDT 控制台输出未显示在带有路径的调试中,也未显示在没有路径的运行中

C++ 跨平台 MP3 解码器?

c - 用antlr解析评论

ruby - 在 Ruby 中阻止评论

c++ - 如何在 C++ 中实现通用 DOM 数据结构?

c++ - 如何测量时间?

gcc - MSYS2 GCC 在禁用 SSE 的情况下将浮点运算的双倍归零

javascript - 删除 PHP 中所有 REAL Javascript 注释

c++ - C++ 中的错误消息 "Undefined reference error to"