函数体内的 url 是如何编译的
我只是将一个 url 粘贴到我的代码中,忘记注释它,但我很惊讶地看到 MSVC++ 成功编译了它。我的代码是这样的,
void my_function()
{
http://www.google.co.in/
}
怎么会被MSVC++编译呢?
I just pasted a url to my code, and forgot to comment it, but I was surprised to see MSVC++ compiled it successfully. My code is like this,
void my_function()
{
http://www.google.co.in/
}
How come this gets compiled by MSVC++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,
http
后跟 冒号 被 C++ 视为标签,您可以在goto
语句中使用它(如goto http;
),其余部分(即//www.google.co.in
)被视为单行注释。这就是它被编译的原因。查看更多,
顺便说一句,我认为您编写的示例不会被编译。 url 后面至少应该有一行代码,只有这样它才会在我的电脑上编译。我正在使用 MSVC++ 2008。
Actually,
http
followed by a colon is treated as a label by C++, which you can use ingoto
statements (likegoto http;
), and the rest (i.e//www.google.co.in
) is treated as single line comment. That's why it gets compiled.See more,
By the way, I don't think the example you've written would get compiled. There should be at least one line of code after the url, only then it gets compiled on my PC. I'm using MSVC++ 2008.
C++ 中不带引号的
//
是注释。因此,在删除注释后,您的代码将如下所示:所以
http:
只是一个可以与goto
一起使用的标签。Unquoted
//
in C++ is a comment. So after stripping comments, your code will look like this:So
http:
is just a label that can be used withgoto
.