简体   繁体   English

为什么在C和C ++代码中插入URL有效?

[英]Why does inserting URLs in C and C++ code work?

Why does the following code compile? 为什么以下代码编译? Which section of the language allows URLs to be added in C and C++ code? 该语言的哪个部分允许在C和C ++代码中添加URL?

int main()
{
     http://www.stackoverflow.com
     return 0;
}

Thanks in advance, Castro. 提前谢谢,卡斯特罗。

If you compiled with warnings, you would notice: 如果你编译了警告,你会注意到:

warning: label ‘http’ defined but not used

That should be indicative enough of the problem here. 这应该足以说明这里的问题。

The http: text is treated as a label. http:文本被视为标签。

Followed by // negating the remaining text as a comment, ignoring it. 接下来//否定剩下的文本作为评论,忽略它。

http://www.stackoverflow.com

Even the SO syntax colour schemes indicated as above show this to be true, as the section after the http, is treated as a comment (grayed out). 即使是如上所示的SO语法颜色方案也表明这是真的,因为http之后的部分被视为注释(变灰)。

It's because the compiler treats http: as a label and // whatever as a comment. 这是因为编译器将http:视为标签, // whatever视为注释。 This is perfectly legal code. 这是完全合法的代码。

Unless you use goto http; 除非你使用goto http; somewhere however, it'll be completely useless code. 然而,在某处,它将是完全无用的代码。

In your code http is just a label and //www.stackoverflow.com is a comment. 在您的代码中, http只是一个标签而//www.stackoverflow.com是一个评论。

Also note that 另请注意

int main()
{
     http://www.stackoverflow.com
}

or 要么

int main()
{
 http://www.stackoverflow.com
 http://www.facebook.com
 return 0;
}

won't compile. 不会编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM