4 c++ compiler-construction goto function compiler-warnings
我只是在我的代码中粘贴了一个url,忘了发表评论,但我很惊讶看到MSVC++成功编译了它.我的代码是这样的,
void my_function()
{
http://www.google.co.in/
}
Run Code Online (Sandbox Code Playgroud)
为什么这会被MSVC++编译?
实际上,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!
}
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我不认为你编写的例子会被编译.在url之后应该至少有一行代码,然后才能在我的PC上编译.我正在使用MSVC++ 2008.