HNNewShowAskJobs
Built with Tanstack Start
URL in C (2011)(susam.net)
44 points by birdculture 5 days ago | 15 comments
  • p0w3n3d4 hours ago

    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.

  • eps2 hours ago

    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.
    • pwdisswordfishy2 hours ago |parent

      It's not as needed in C given that you can use #if 1

      It is handy in C derivatives, though.

  • rplnt2 hours ago

    This puzzle would become extra trivial with syntax highlighting.

  • tromp2 hours ago

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

    error: redefinition of label 'https'

  • gblargg5 hours ago

    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.

  • raverbashing4 hours ago

    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

  • writebetterc5 hours ago

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

    • dxroshan34 minutes ago |parent

      It's a puzzle. Nobody is going to put a URL amid your code. There is no harm in using // for comments.

      • writebetterc16 minutes ago |parent

        It's a joke

    • danhau2 hours ago |parent

      How is this related to the article?

      • wkjagt2 hours ago |parent

        Solve the puzzle and you'll know :-)

  • anonnon4 hours ago

    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.

    • pwdisswordfishy2 hours ago |parent

      Or if you use a syntax highlighter.

      • anonnonan hour ago |parent

        Yes, I don't know why people are downvoting me. Have these people never seen C code using goto-based error handling?