 |
 |
Probably another stupid mistake,,,
|
 |
|
 |
|
Senior User
Join Date: Sep 2000
Location: UK
Status:
Offline
|
|
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
|
|
What's the error message you get?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Sep 2000
Location: UK
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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'."
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|