3 ms·
URL in C (2011)
- gblargg 11mo agoI 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.
- writebetterc 11mo agoThis is why you should only use /* */ as your comment style.
- danhau 11mo agoHow is this related to the article?
- wkjagt 11mo agoSolve the puzzle and you'll know :-)
- dxroshan 11mo agoIt's a puzzle. Nobody is going to put a URL amid your code. There is no harm in using // for comments.
- writebetterc 11mo agoIt's a joke
- dxroshan 11mo agoMy bad, I thought you are serious.
- p0w3n3d 11mo agoQuite 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.
- raverbashing 11mo agoOf 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
- dhosek 11mo agoI remember working on some code back in ’99 when the other dev on the project used // comments in C code which, it turned out, were supported by the C compiler we were using, but which broke the embedded SQL preprocessor.
- _zagj 11mo agoClearly, 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.
- pwdisswordfishy 11mo agoOr if you use a syntax highlighter.
- _zagj 11mo agoYes, I don't know why people are downvoting me. Have these people never seen C code using goto-based error handling?
- NackerHughes 11mo agoI wouldn't be surprised if a fair majority of them have been taught to see goto as nothing but a vestige of the 70s which should never be used under any circumstances except as a meme or to deliberately obfuscate code. I have recently become quite fond of goto-based error handling and find it a lot cleaner and more readable than the if-else-mountains you otherwise end up with. I just make sure to leave a comment with a link to xkcd.com/292 so anyone else reading it knows I'm aware of what I'm doing. Now with this URL trick I can do both in one line. :)
- elcapitan 11mo agoAnd the corresponding `goto http` is the chef's kiss :D love it
- dhosek 11mo agoI mean, I’ve not written C code in decades¹ and this didn’t cause a second’s pause. ⸻ 1. Long enough ago that the only practical way to get syntax highlighting was to run a separate program on the source code to generate a TeX document.
- tromp 11mo agoYou can only have one URL for each scheme though, else your compiler will report something like error: redefinition of label 'https'
- rplnt 11mo agoThis puzzle would become extra trivial with syntax highlighting.
- eps 11mo agoNice. Another neat comment-based construct is the good old: //* foo /*/ bar //*/ It yields 'foo' as is, and 'bar' if the first slash is removed.
- pwdisswordfishy 11mo agoIt's not as needed in C given that you can use #if 1 It is handy in C derivatives, though.
- askl 11mo agoAt 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.
- rts_cts 11mo agoThat's exactly how we found an accidental copy/paste of an internal URL in our source code.
- 1vuio0pswjnm7 11mo agoWouldn't there be a warning about an unused goto label
- alilikestech 11mo agoThis is very neat.