Reputation:
I'm trying to use message queue to send and receive messages between father and son processes, I used enum to set message types for msgrcv but it seems that it ignores that information:
enum children {
e_father_child1 = 1,
e_father_child2 = 2,
e_child1_father = 10,
e_child2_father = 20
};
and the command is:
queue_indc = msgrcv (msgid, &msg, sizeof (msg.m_data), e_child1_father, 0);
It works if I change the argument from enum type to int but I was wondering why isn't it working as enum and is there any other way to make it work.
Thanks in advance!
Upvotes: 0
Views: 214
Reputation: 257
It seems that msgtyp is treated as a long as opposed to just a regular int. And enums are treated as just regular ints.
ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
So I am thinking the compiler is having troubles converting an 'enum' to a long, where converting an 'int' to a long can be done more easily. What if you tried casting the msgtyp to a long? When I compiled the above code that you provided it worked without any cast however.
e.g.
queue_indc = msgrcv (msgid, &msg, sizeof (msg.m_data), (long) e_child1_father, 0);
Here is an article that may help explain the enum type:
Upvotes: 1