09-25-2003, 06:05 PM
Pages: 1 2
09-25-2003, 08:36 PM
It compiles exactly the same way as equivalent IF THEN/ELSEIF THEN/ELSE/ENDIF statements. (as far as I know)
Use the /A command line switch with BC.EXE and it will put assembler in the listing file.
Use the /A command line switch with BC.EXE and it will put assembler in the listing file.
09-25-2003, 09:54 PM
Yup! SELECT...CASE...END SELECT and IF...ELSEIF...ELSE...END IF structures compile exactly. But if I may add, SELECT CASE is a more cleaner way of going about things 8)
09-26-2003, 02:05 AM
Does it compile the same way in C? If not, how does it work in C?
09-26-2003, 04:22 AM
As far as I know, C doesn't allow variables in the case statements. So I would expect C to load the variable being examined into a register, then for each case generate a cmp/j** pair to skip over the code within if the condition isn't met.
09-26-2003, 10:10 PM
Come to think of it, I'm starting to think that SELECT CASE works like this:
The reason I see it this way is because of the break; statement in C. It jumps to the correct answer, but if you don't mention break;, it'll keep going.
Code:
IF true THEN GOTO true statement
The reason I see it this way is because of the break; statement in C. It jumps to the correct answer, but if you don't mention break;, it'll keep going.
09-26-2003, 10:17 PM
Quote:Does it compile the same way in C? If not, how does it work in C?
aga, i think it would be better to ask this question in the general forum or a C/C++ forum. The chances are u will get a more specific or better answer there.
09-27-2003, 01:33 AM
in c, switch() is implemented as a jump table. i'm not sure what it is, but by what i gathered:
a. cases can be only constants
b. (expression) is evaluated ONLY ONCE, unlike in several IFs.
c. it is faster than IFs... besides, but i never realized how (except the only one-time eval)
[Flexibal>
a. cases can be only constants
b. (expression) is evaluated ONLY ONCE, unlike in several IFs.
c. it is faster than IFs... besides, but i never realized how (except the only one-time eval)
[Flexibal>
09-28-2003, 06:45 AM
So no chance of an on-teh-fly B tree then.....
09-28-2003, 08:54 AM
Why would you ever use a B tree for program flow control?
Quote:[in a C switch statement] (expression) is evaluated ONLY ONCE, unlike in several IFs.Oh right, I forgot to mention that. QB's SELECT command works the same way, it evaluates only once like C, but it doesn't use a jump table.
Pages: 1 2