Hello, I would like to use a mailbox and i've studied the RTX manual. But i still have a problem.. I want to use the message of the mailbox in a switch, but i cannot understand what i should pass to the switch.
Here is the part of the code:
void* msg; while(1) { os_mbx_wait(MsgBox,&msg,0xffff); switch (*msg){ case button_right : counter +=2; break; case button_up: counter ++; break; case button_down: counter --; break; case button_left: counter -=2; break; case button_select: break;
And the error i receive is:
tisifone_task_2b.c(73): error: #31: expression must have integral type tisifone_task_2b.c: switch (*msg){
The message came from another task which send a pointer to an int.
How can i work with a message coming from a mailbox?? Many thanks.
The error message clearly tells you what the problem is:
error: #31: expression must have integral type
(which is, in fact, a standard requirement of the 'switch' statement in the 'C' programming language)
So ask yourself: "what type does the expression *msg have?"
Thanks for your answer, but the problem is that the function
os_mbx_wait
(and also the send function) need a pointer to a void. So i cannot use a pointer to an int such as
int *msg
because then i will have the opposite error message. So i cannot understand how can i get out of this trouble. Thanks
Just a couple of questions here.
Have you spent a bit of time with a decent book on C programming? Have you read the chapter about pointers? Have you read about type casting? Have you read about the meaning of void pointers? What is special about void pointers?
Yes i read a lot and i'm able to work with pointers. I know it seems a very stupid question, but i wrote it in the forum just because i cannot solve it and maybe i forgot something or i made some mistake that i cannot see. But thanks, i will try to solve it by myself.
Whatever void points to is not specific so you can't use it in a switch. Use an int * (or whatever type the data item is) and cast to void * where needed. Normally void * in functions are used to signal that the function doesn't care what's really pointed at.
In your case I'd add a cast (void *) in the call to the function that expects void.
Andrew
> In your case I'd add a cast (void *) in the call to the function that expects void.
That should have read (void **), since the routine writes a pointer to the location of the actual mailbox item. There's a message (e.g. an int), the address of that msg, (e.g. int *p=&msg) and a pointer to that pointer, which the mailbox routine uses.
It works.. i didn't think at this kind of possibility..
many thanks, BR
"It works.. i didn't think at this kind of possibility.."
Which is the reason you shouldn't write "Yes i read a lot and i'm able to work with pointers." but instead go back and take a reread about pointers, typecasts etc in some good C book. It really is important knowledge.