logoalt Hacker News

URL in C (2011)

58 pointsby birdculturelast Thursday at 7:42 AM16 commentsview on HN

Comments

p0w3n3dtoday at 7:59 AM

Quite a time ago, my colleague accidentally committed a Youtube url to our Java codebase (middle-click accidental paste, no code review at that time). We had some laughing moments when we discovered it, as it was compelling evidence that he was watching videos during work, and even we knew what he was watching at that time.

epstoday at 10:38 AM

Nice.

Another neat comment-based construct is the good old:

  //*
     foo
  /*/
     bar
  //*/
It yields 'foo' as is, and 'bar' if the first slash is removed.
show 1 reply
rplnttoday at 10:10 AM

This puzzle would become extra trivial with syntax highlighting.

tromptoday at 10:05 AM

You can only have one URL for each scheme though, else your compiler will report something like

error: redefinition of label 'https'

gblarggtoday at 7:47 AM

I do this to embed shell commands at the beginning of short one-file C/C++ programs to execute when hitting an F key in my text editor. I usually put very basic compile-and-run commands. It's wrapped in #if and #endif which are comments in many shells. I end the commands with exit so it doesn't try to execute the code as commands.

raverbashingtoday at 8:25 AM

Of all the (ahem, not as many as hoped) things C++ got right, // comments are one of the best ones

And I'm glad it now is part of C as well

askltoday at 12:29 PM

At least when using -Wall the compiler will give you the warning

  <source>:5:5: warning: label 'https' defined but not used [-Wunused-label]
as a hint.
writebetterctoday at 7:55 AM

This is why you should only use /* */ as your comment style.

show 2 replies
anonnontoday at 8:30 AM

Clearly, the "http:" is parsed as a label (for goto), and the subsequent "//", as a C++ or C99 comment. This shouldn't give you more than a moment's pause if you know C.

show 1 reply