Why constant ints in switch case expressions?

  • Thread starter Brian J. Sayatovic
  • Start date
R

Roedy Green

For example, this execution model would work for both:

Another way to do it is insist the values of the case variables be
unique. If they are not you get some sort of exception.

Most of the time the values are stable, it is just they have to be
computed once at run time. Perhaps just insisting they have final
values would suffice.

You want to avoid having to implement with nested ifs. You also want
to avoid having to fool around testing the variable case labels every
time you use the switch.
 
R

Roedy Green

D

Dale King

Roedy Green said:
ranges can be much more efficiently implemented by a compiler than by
hand, when the range limits are known at compile time, using an inline
binary search.

Right, that's what I said in that RFE and even provided an example showing
this.
The construction of a switch should be postponable at least until
first use. THEN lock the values.

That's a completely separate question, that I did not address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top