Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

C compilers have been optimising switch statements like this since at least the 90s, haven't they?


I'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.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: