3

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...

erogol
  • 13,156
  • 33
  • 101
  • 155

1 Answers1

6

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

ewall
  • 27,179
  • 15
  • 70
  • 84
sdg
  • 4,645
  • 3
  • 32
  • 26