Get the latest tech news

Cursed fire or #define black magic


Have you ever wondered whether it is possible to write fully functional code using only the #define directive in C? It's well-known that the C++ templates are Turing complete, developers even write ray tracers that do all evaluations at compile time (instead of runtime). What about the C preprocessor? As it turns out, the question is a bit more complex than one might think.

I can't run graphics mode, but my terminal supports the\033[ escape sequence, so a single print instruction is enough to draw the fire! I declare CONCAT, the macro command to merge two tokens, and all problems disappear: decrement operates fine using numeric constants, not expressions. An ordinary human brain will tell in a few seconds what the below very trivial code should be compiled into, but GCC will need many exabytes of memory and many years to give the answer.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of black magic

black magic

Photo of Cursed fire

Cursed fire

Related news:

News photo

Using black magic to make a fast circular buffer (2017)