-- Leo's gemini proxy

-- Connecting to michal_atlas.srht.site:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

This code is a completely valid C source file:


$($){
  return $
;}

main () {
  printf("%d\n", $(23))
;}

and I don’t even mean that it’s part of a project or whatever, this verbatim compiles in both gcc and clang!!! Go ahead try it, I’ll wait.


Okay, the warnings spoil a bit of the fun, it’s still interesting though, I wondered what are valid characters in an identifier, since I was kinda let down by the fact that you have the entirety of UNICODE at your disposal but not most of ASCII. So I tried all the ASCII characters, interestingly enough NULL didn’t pose a problem, the compiler simply ignored it, and everything else was either ignored or threw an error as expected, except $.


$ for some reason works, GCC doesn’t even give you a warning (Although that’s not its job, that should be a linting thing). The next part is that everything in C is assumed to be int unless you know otherwise, so printf even though undeclared just happens to fit the signature it links against, and doesn’t cause problems. Arguments seem to simply be bound in a new scope after the function, which is logical now that I say it out loud, but allows us to just shadow the function $ with the argument $, and what’s the type of $? Since it’s undeclared it’s just int again, same for both the variable and function.


That’s it, it’s not really too interesting but it’s something I discovered a long time ago, and find quite amusing and keep showing around.

-- Response ended

-- Page fetched on Sat May 11 11:48:58 2024