函数体内的 url 是如何编译的

发布于 2024-10-08 23:24:41 字数 166 浏览 0 评论 0原文

我只是将一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小傻瓜 2024-10-15 23:24:41

实际上,http 后跟 冒号 被 C++ 视为标签,您可以在 goto 语句中使用它(如goto http;),其余部分(即//www.google.co.in)被视为单行注释。这就是它被编译的原因。

查看更多,

 void your_function()
 {

        http://www.google.co.in/

        https://www.crazy_c++.com/

        ftp://c++_is_fun.edu

        //your code here
        int i = 10 ; //atleast one line of code is needed here to get compiled!
 }

顺便说一句,我认为您编写的示例不会被编译。 url 后面至少应该有一行代码,只有这样它才会在我的电脑上编译。我正在使用 MSVC++ 2008。

Actually, http followed by a colon is treated as a label by C++, which you can use in goto statements (like goto http;), and the rest (i.e //www.google.co.in) is treated as single line comment. That's why it gets compiled.

See more,

 void your_function()
 {

        http://www.google.co.in/

        https://www.crazy_c++.com/

        ftp://c++_is_fun.edu

        //your code here
        int i = 10 ; //atleast one line of code is needed here to get compiled!
 }

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.

木緿 2024-10-15 23:24:41

C++ 中不带引号的 // 是注释。因此,在删除注释后,您的代码将如下所示:

void my_function()
{
    http:
}

所以 http: 只是一个可以与 goto 一起使用的标签。

Unquoted // in C++ is a comment. So after stripping comments, your code will look like this:

void my_function()
{
    http:
}

So http: is just a label that can be used with goto.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文