No more fall through in case statement?

0ffh frank at youknow.what.todo.interNETz
Sat Jan 5 04:37:27 PST 2008


Janice Caron wrote:
> On 1/5/08, BC <notmi_emayl_adreznot at hotmail.com.remove.not> wrote:
>>> The way I see it, the advantage of "switch/case" over "if" is that the 
>>> compiler might be able to find cool ways to optimize the code (e.g 
>>> binary search, sparse array lookup, table lookup, whatever). If the 
>>> compiler can't do that, well then, what's the point of using it at all 
>>> when "if" is perfectly expressive already?
>> 
>> Do you know if the compilers actually do this?
> 
> Me? Hell no! I don't write compilers. [...] I do know the answer for at 
> least one ancient compiler of old. [...] But that was then and this is now 
> and things are bound to be different.

FWIW I totally agree with you that there is virtual certainty that some
kind of optimisation (jump table, binary search tree, etc.) is actually
used in each of DMD and GDC and more or less any optimising compiler.
Whatever the target machine is, those are bound to be faster than a
linear chain of if-else-ifs (except for extreme cases).

regards, frank



More information about the Digitalmars-d mailing list