3 ms·
You can turn a switch statement into a series of ? : switch(a) { case x: do1(); break; case y: do2(); break; default do3();
by szc 8y ago
You can turn a switch statement into a series of ? :
switch(a) {
case x:
do1();
break;
case y:
do2();
break;
default
do3();
break;
}
becomes
a == x ? do1() : a == y ? do2() : do3();
These structures can be seen in the minimized version (and a few other IOCCC winners :-).
This code likely doesn't optimize quite as well. Several cute things you can do with switch statements cannot be translated so easily.
- pjc50 8y agoAha, found a partially-deobfuscated version: https://gist.github.com/slacka/8306176 https://gist.github.com/slacka/8306176 The instruction decode mechanism is a chain of "e--||(expression), e--|| ..." expressions. At the point where e-- is zero the expression will be evaluated. The program makes heavy use of the equivalence between "index[pointer]" and "pointer[index]", presumably to save brackets.
- szc 8y agoVery true || !false. The 3rd, 4th and 5th ways to encode a switch can be done using <disconnected>