把 struct msg 改一下, struct msg { long int msgtype; int count; unsigned int data[35]; } 其中count记录总共有多少个 data,这样就可以发送变长的消息了,比如你要发10个unsigned int,那么 struct msg mymsg; mymsg.msgtype = XXXX; mymsg.count = 10; /* 发消息时,不用把整个msg都发出去,只需要发有效的内容 */ len = sizeof(msg) - sizeof(unsigned int) * (35-mymsg.count); mq_send(queue, &mymsg, len, 0); /* 接收后, 根据收到的 count来取数据 */ struct msg rcvmsg; mq_receive(queue, &rcvmsg, sizeof(rcvmsg), NULL); printf("%d data received\n", rcvmsg.count);