8 ms·
Apparently you would see this commonly in hardware design back in the day because one of the compilers picked this up and mapped it to a look up table in the ri
by Traster 7y ago
Apparently you would see this commonly in hardware design back in the day because one of the compilers picked this up and mapped it to a look up table in the right way where other expressions might not be picked up correctly. I could easily see the same trick working in a software compiler too.
- yvdriess 7y agoJS's switch is a different beast. The OP's statement doesn't work in C/C++ because its case labels need to be unique. You also would need a large number of case statements before a modern optimizing compiler will decide a switch statement is worth a jump table rather than conditionals.
- archi42 7y agoIn fact, the compiler building a static switch table from non-constant expressions sounds a little bit impossible ;-)