问题
I try to send integer by msg queue but the function mq_send(mq, &val , sizeof(val), 0); is working for only char type pointer so is there any way to send integer to queue with another function or same function.
Regards...
回答1:
Do not read the char* in this case as the only allowed datatype.
Many *ix API use char as a generic buffer pointer.
View the interface therefore as taking a pointer to buffer and the size of the buffer.
That buffer can be anything you like, from a single int, to a struct, seralized string representation of your class, or just about anything else in memory.
int i;
mq_send(mq, (char *) &i, sizeof(i), 0);
Should work (not tested)
Good Luck
来源:https://stackoverflow.com/questions/5247041/how-to-send-integer-with-message-queue-with-posix-api-in-linux