how does url within function body get compiled

前端 未结 2 1437
谎友^
谎友^ 2020-12-03 23:23

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(         


        
相关标签:
2条回答
  • 2020-12-04 00:18

    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.

    0 讨论(0)
  • 2020-12-04 00:28

    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.

    0 讨论(0)
提交回复
热议问题