开发者

How to send integer with message queue with POSIX API in linux?

I try to send integer by msg queue but the function mq_send(mq, &val , sizeof(val), 0); is working开发者_如何学Python for only char type pointer so is there any way to send integer to queue with another function or same function.

Regards...


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜