How to compile url inside function body

I just pasted the url into my code and forgot to comment on it, but I was surprised to see that MSVC ++ compiled it successfully. My code is as follows:

void my_function() { http://www.google.co.in/ } 

Why is this compiled by MSVC ++?

+4
source share
2 answers

In fact, http followed by a colon is considered a C ++ label that you can use in goto (e.g. goto http; ), and the rest (i.e. //www.google.co.in ) is considered as a single line comment. That is why it compiles.

More details

  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 do not think that the example you wrote will be compiled. There must be at least one line of code after the URL, only after that it compiles on my PC. I am using MSVC ++ 2008.

+8
source

Optional // in C ++ - comment. Therefore, after removing the comments, your code will look like this:

 void my_function() { http: } 

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

+1
source

Source: https://habr.com/ru/post/1333230/


All Articles