Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - The switch()

The switch()

Discuss topics that apply across the products, such as the PocketC language, or development in general

Postby cable_guy_67 on Mon Apr 28, 2003 3:12 pm

Hello all,
I have been working on something that works perfectly for a:
switch(x_str){
case "01":

But I am not accessesing all my cases. Can you nest switch() statements as long as you place the } after the default: ?

Example code:

//comming from a switch()
case "01":
case "60":
case "61":
bopx_str=bopx;
bopy_str=bopy;
if(house_data[hy][hx][3]==(bopx_str+bopy_str)){
alert("Pick a location to move that to.");
wait_for_tap();
placex=(px-10)/20;
placey=(py-30)/20;
if ((placex==4)&&(placey==0)){
switch(bopx_str+bopy_str){
case "10":
alert("You have chosen to move the male tray to the operating theater.");
FastBmp(10,30,8);
house_data[0][0][0]=8;
house_data[0][0][1]=0;
house_data[0][0][2]=1;

And it goes on to close all open statements.
I just want to be sure this is legal and find my problem elsewhere in the code. I have an old C manual and it doesn't say one way or the other.

Thanks,
Mark
cable_guy_67
 
Posts: 92
Joined: Mon Mar 31, 2003 2:28 am
Location: USA

Postby jstadolnik on Tue Apr 29, 2003 12:42 am

Nested switches should work (at least they're supposed to).

Try doing a StrLen() before on string before you pass it to the switch. You may have a stray whitespace character in the the string?

Joe

The PToolboxLib guy.
http://www.geocities.com/retro_01775/PToolboxLib.htm
jstadolnik
 
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Postby cable_guy_67 on Tue Apr 29, 2003 10:39 am

I think you are right about checking the variable for the switch. Realistically, how many case: statements is too much? I have 80 different ones (main case:'s and nested cases:'s) and I can see the lag on the actual palm. It runs great on the pose but runs slowly on my IIIc. Would it be better to break them down into 4 sections and direct accordingly to increase speed. As I am totally new to Pocket C (and C for that matter) I have a lot of deep if/else loops and calling a function from a function. Thanks for the info Joe. And for any newcomers I have some book recommendations.

1: Palm Programming for the Absolute Beginner.
. I know this has been described a lot here but it is invaluable in really getting Pocket C. A bit old but you can get it for around $20 on amazon.
2: A Step-by-Step Guide to C Programming by Jean Paul Corriveau.
or
3: Complete Book of C Programming by Barry M Austell-Wolfson and R Derek Otieno.
. Of these two I like the first better. They are from 1999 and 2000 and written like textbooks with suggestions and examples. One of these books will help you when all other documentation fails! I had them sent to me from our wonderful Public Library System. They have lots of books that rarely get requested.

After all, I went from total maroon to having a competent grasp of the language with 2 hard weeks, you can too.
Just my two cents. :D
And Congrats Joe, you sounded pumped re:new version of PToolBox.

Mark
cable_guy_67
 
Posts: 92
Joined: Mon Mar 31, 2003 2:28 am
Location: USA

Postby jstadolnik on Tue Apr 29, 2003 12:06 pm

Try using integers as the switch variables, In general they work faster than strings, and this may allow the compiler to make further optimizations.

Also, try breaking up your switch structures so that they each have fewer case statements.

One more... check out the speedopts.c file in the PToolbox release. Specifically item #11. It shows a technique that's even faster than a switch-case.

Joe



The PToolboxLib guy.
http://www.geocities.com/retro_01775/PToolboxLib.htm
jstadolnik
 
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Postby wolfgang on Tue Apr 29, 2003 2:34 pm

Probably the fastest substitute for long switch clauses or eternal if/elseif lists: If the possible range of values is limited (e.g. let's say variable myvar can only hold values from 1...10, then the fastest is to have an array of function pointers and call the respective functions. Each function contains the code from one case clause of your switch statement.

// define the functions with the necessary code

myfunc1() {....}

myfunc2() {...}

... and so on

main ()
{
int myvar;
pointer myarr[100];

myarr[1] = myfunc1; // pointer to first function
myarr[2] = myfunc1; // pointer to second function
...and so on

... now determine the switch variable somehow....

// here comes the switch replacement - this calls the proper
// function based on what value myvar has. If myvar == 1, it calls
// myfunc1(), if myvar is 2, then it calls myfunc2(), and so on

(*(myarr [myvar])) (); // that's all!!!
}

This is blazingly fast, independent of the number of different cases.

Wolfgang


Composing music on the PocketPC! - http://www.pdamusician.com
Composing music on the PocketPC! - http://www.pdamusician.com
wolfgang
 
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Postby cable_guy_67 on Tue Apr 29, 2003 4:50 pm

I haved saved this thread on my local machine and will use those suggestions. Thanks Joe and Wolfgang for the input, it answered all my questions. Wolfgang, your tutorials were the first I learned to code in Pocket C with. I like the simple explanations.

Off to implement &
read more PToolBox docs...at least the're not terse. :D

Mark
cable_guy_67
 
Posts: 92
Joined: Mon Mar 31, 2003 2:28 am
Location: USA


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron