开发者

Why does inserting URLs in C and C++ code work?

Why does the following code compile? Which section of t开发者_如何学Pythonhe language allows URLs to be added in C and C++ code?

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.

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).


It's because the compiler treats http: as a label and // whatever as a comment. This is perfectly legal code.

Unless you use 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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜