|
-
September 25th, 2008, 12:21 PM
#11
Re: Why do we have only costant value's or constant value expression in SWITCH statement
 Originally Posted by Graham
What?
What does "case labels are evaluated without order" mean?
The only difference between switch and FORTRAN's computed GOTO is syntactic sugar. I could do anything that switch can do in FORTRAN. The only complication is that I would need to map (the used values of) the switch variable on to a consecutive sequence of integer values starting at one. That the compiler in C++ does this for me is, as I said, syntactic sugar.
You can implement any control structure available in C++ in assembly and that would involve gotos. So if you would call all control structures "glorified gotos" I would agree, but if you single out the switch, I don't.
As a control structure the switch has a unique property. The label cases are in no specific order. That's what characterizes a switch and that's for example why an if-chain isn't functionally equivalent with a switch. That's also why a switch can be implemented in O(1) using say a table of some kind.
The fact that you (or a compiler) can accomplish the functional equivalent of a switch with gotos in some language is irrelevant. The switch has a unique property that no combination of other control structures can mimic. It's not just a "glorified goto".
Last edited by _uj; September 25th, 2008 at 04:14 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|