LINUX.ORG.RU

поле msgsz в функциях msgsnd и msgrcv


0

0

Man:
       To send or receive a message, the calling process allocates a structure of the following general form:

            struct msgbuf {
                 long mtype;     /* message type, must be > 0 */
                 char mtext[1];  /* message data */
            };

       The mtext field is an array (or other structure) whose size is specified by msgsz, a non-negative integer value.

А в учебнике приведён код типа

msgsnd(id, &msg, sizeof(msg), 0);

Т.е. в этом случае размер будет на sizeof(long) больше. Учебник ошибается?
★★★★★

Да, учебник ошибается. Первое поле структуры msgbuf не является частью сообщения, поэтому код должен быть таким:

msgsnd(id, &msg, sizeof(msg) - sizeof(long), 0);

DmVo
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.