3 ms·
C compilers have been optimising switch statements like this since at least the 90s, haven't they?
by mooism2 14y ago
C compilers have been optimising switch statements like this since at least the 90s, haven't they?
- opinali 14y agoI'd be surprised if they haven't been doing that since the very beginning -- the first compilers from K&R. This is the reason why switch only works with integral types (and not with any comparable value such as strings): it's intended to be compiled into an efficient table lookup if the range of case values is dense enough.