why # followed by a number seems do nothing in C plus plus

心已入冬 提交于 2019-12-05 09:49:16

That is a line directive. Most preprocessors output these to tell the compiler which lines it actually is in the original source file.

As the preprocessor can add many (sometimes hundreds or even thousands) lines to the source it provides to the compiler, the compiler needs to way to keep track of the line numbers of the original source file. This is done through special directives such as that.

When I compile it with GCC, I get the following warning:

warning: style of line directive is a GCC extension [enabled by default]

In other words, this is not Standard C++, but a specific compiler extension (a preprocessor extension in this case and, in particular, a line directive).

You should therefore refer to the compiler's documentation to check what exactly is allowed and what is not. For instance, see this.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!