7 Comments

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

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

Expand full comment

"… without making it unreadable."

Hah, that's what you think! 😅

Expand full comment

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

Expand full comment

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

Expand full comment

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

Expand full comment

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