Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Probably another stupid mistake,,,

Probably another stupid mistake,,,
Thread Tools
Senior User
Join Date: Sep 2000
Location: UK
Status: Offline
Reply With Quote
Jun 29, 2004, 04:01 PM
 
Hi,

Once again, I guess I'm doing something silly, but I can't get this to work( x is a UInt16):

switch(x)
{
case 440:
di = 4009;
break;

case 466:
di = 4010;
break;

case 523:
di = 4011;
break;

case 622:
di = 4012;
break;

default:
di = 4010;
break;
}

Any ideas?
(I'm using C)

Thanks,

David
     
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Jun 29, 2004, 04:10 PM
 
What's the error message you get?
     
iMacfan  (op)
Senior User
Join Date: Sep 2000
Location: UK
Status: Offline
Reply With Quote
Jun 29, 2004, 04:15 PM
 
Originally posted by Catfish_Man:
What's the error message you get?
It compiles fine, but the function which is passed the variable di does not do what is required, when just beforehand, the same function, without a switch determining the value of di, works perfectly, making me think that the switch is the root of the problem.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 29, 2004, 05:21 PM
 
Aside from being heavy in hardcoded magic numbers, I can't see anything wrong with the switch statement. And I don't really understand the scenario well enough to posit a guess as to what else it could be. All I can think now is just to check your magic numbers.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Grizzled Veteran
Join Date: Feb 2003
Status: Offline
Reply With Quote
Jul 6, 2004, 02:10 AM
 
I don't see anything wrong with it either... possibly something is wrong other than the switch?
     
Mac Elite
Join Date: Feb 2001
Location: Washington, DC
Status: Offline
Reply With Quote
Jul 6, 2004, 07:03 PM
 
Are you passing the variable di by value or by reference?

by value: void foo( UInt16 di );

by refrence: void foo( UInt16 *di );
/Earth\ Mk\.\ I{2}/
     
Forum Regular
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jul 8, 2004, 08:29 AM
 
add some debug code,

ex:
fprintf(stderr,"Before case %d\n",x);
.
case(x) ...
.
fprintf(stderr,"After case %d\n",di);

and so on, so you se the value for x,di, but I think Earth Mk. II is right, you are passing the value of x, not the pointer (reference).
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 9, 2004, 02:43 AM
 
Originally posted by geran:
I think Earth Mk. II is right, you are passing the value of x, not the pointer (reference).
Did he say anything to indicate he's trying to use a pointer?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:38 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2