@nixCraft heh, clever

the url breaks down into a label and a comment XD

@nixCraft That's probably the easiest and most boring of this kind of puzzles I've seen so far.
@nixCraft c99 really does give JavaScript a run for it’s money.
@tonytins @nixCraft this works in js too ;-)

@tonytins

And indeed, this URL-in-code hack doesn't work in pre-C99 standards 😉

@nixCraft

@nixCraft I get it = the https: is a label and the // is a comment
@nixCraft I guess with all warnings turned on it would tell you about the unused label https…

@toriver @nixCraft

A good C compiler should probably not warn about unused labels, but warn about using labels... 🤷

@nixCraft somehow this is cute
@nixCraft Looks confusing only because there’s syntax colouring in the shell but not in the code
@nixCraft "https:" is just a label and "//" makes everything until the end of the line a comment. Therefore it's valid.
@nixCraft If you compile with warnings enabled, it spoils the thing completely.

@nixCraft without looking at the link..  

https: is parsed as a label and anything after the // is ignored as a comment?

edit: hehe yup, that was it 

@nixCraft Yeah, `https:` is parsed as a `goto` label and the subsequent `//` is a C++ style comment.
@nixCraft Put a second https: link and I'll bet it barfs over a duplicate label.
@stuartl @nixCraft // is not just a C++ comment style, even though more commonly seen there. It's been valid in C for at least C99 and probably even C89/90.
@nixCraft I had thought about the comment, but labels? oh this vents back some old memories
@corujosilva @nixCraft still frequently see "cleanup:" in code from oldheads when breaking out in situations.
@nixCraft That one is old and well known: It’s just a label followed by a comment.
@nixCraft Everybody who got this immediately should think twice about their code style. It took me a bit to remember C has still labels and goto, like a good "somewhat less worse than Assembler" language required...

@mort @nixCraft I got this immediately and I've never written a single label in C in my whole life.

Just because we know our enemies doesn't mean we *are* our enemies.

@dfyx @mort @nixCraft

This. Got it immediately. Very rarely use labels.

Do note, however, sometimes labels are the best way to code. You shouldn't make a habit of it, but complete purity of code isn't a good idea either.

@mort Even far more structured & high level languages like Pascal or Ada still have labels & goto.

@nixCraft Ah this was an easy one:
#include <stdio.h>

int main(void)
{
https://susam.net/
printf("hello, world\n");
goto https;
return 0;
}

Susam Pal

@nixCraft Hm how can I prevent Mastodon from interpreting the url?

@giggls s/ttps/xxps/

@nixCraft

@apicultor @nixCraft Das ist aber ein unschöner Workaround, denn dann müsste ich auch goto hxxps verwenden.
@giggls Not wrong, but there you go. @nixCraft
@nixCraft I got this one, but honestly I was like, "does C have labels???"
@nixCraft Bug: It still compiles if you change https to http despite the many risks of insecure web sites.
@nixCraft i think i forgot about labels being a thing in C since they're such a great way to make spaghetti code and should be avoided
@nixCraft
a bare string with a colon at the end is interpreted as a label, such as those used for "GO TO" operations. Labels don't do anything on their own
The double slashes make the rest of the line a comment. Comments also don't do anything.
The result is that the line with the URL does nothing as there's no code using the label.

@nixCraft In rust you have to quote the URL ;)

fn ai(think: bool, thunk: impl Fn()) {
'https​://susam.net/url-in-ruist.html'
while think {
thunk()
}
}

(Note: Remove the zero-width space I inserted to stop the url being rendered as a url if copy and pasting this code)

@nixCraft works in JS too! :P

@nixCraft A website I maintained had a buggy template that generated the following JS code:

var STATIC_URL = /static/;

and it worked fine! STATIC_URL + "something.css" did generate "/static/stomething.css".

It eventually broke when the static URL got changed to a full URL.

@nixCraft The reason it worked is that /<something>/ is valid JavaScript syntax that defines a regular expression.

STATIC_URL = /static/;

sets STATIC_URL to a regular expression object.

STATIC_URL + "something.css" converts STATIC_URL back to a string in order to join it to the other string, and it turns out that the string representation of a regular expression is just the full regular expression pattern with slashes, so "/static/" here.