为什么#后面跟一个数字似乎什么也没做C加加 [英] why # followed by a number seems do nothing in C plus plus

查看:113
本文介绍了为什么#后面跟一个数字似乎什么也没做C加加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重新生成步骤:

将以下行插入到c ++源代码的任何一行。

insert the following line into any line of your c++ source code.

#1234

任何行,包括第一行,最后一行。即使你可以在这样的函数头和正文之间输入。

Any line including the first line, the last line. Even you can input between function header and body like this.

int foo()
#1234
{
return 0;
}

这个数字可能很长,我测试了超过170个字符。
如果你添加任何非数字字符,你会得到一个编译错误。

The number can be very long, I tested more than 170 characters. If you add any non-numeric character, you will get an compile error.

我的问题是:为什么#后面跟一个数字不破坏编辑,而#后跟一个非数字字符。

My question is: why # followed by a number doesn't break the compile, while # followed by a non-numeric character does.

感谢大家的时间。

推荐答案

这是一个行指令。大多数预处理器输出这些信息告诉编译器它实际上是在原始源文件中的哪些行。

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.

这篇关于为什么#后面跟一个数字似乎什么也没做C加加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆