7 Comments
User's avatar
Anthony DeRobertis's avatar

As silly as it is nowadays, switch just being a glorified goto was used seriously for manual loop unrolling. Let me introduce Duff's Device: https://en.wikipedia.org/wiki/Duff%27s_device

Expand full comment
Florian Degner's avatar

Nice. Now I'm curious what other creative (ab)uses of C the machines will find once they got trained properly.

Expand full comment
Iustin Pop's avatar

"… without making it unreadable."

Hah, that's what you think! 😅

Expand full comment
Chris Quackenbush's avatar

This is a hilarious technique that implements coroutines using similar switch tricks. https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

Expand full comment
Mikael's avatar

Amazing! I've been using C since 1989 or so and just learned stuff that I wish I never knew :-)

Expand full comment
Alex's avatar

Jumping into an expression is truly cursed, gonna steal that to scare my friends.

Expand full comment
Lakshy Sharma's avatar

This was amazing.

It highlights the simplicity of C and also shows what a monster it can be if we let developers run loose with it.

No wonder large projects like the kernel have coding standards to ensure code comprehensibility.

Expand full comment