create message queues
-
Hiii.. I try to create message queue Inter process communication mechanism, a small program. Here is my code. // struct msgbuf // { // long int mtype; /* type of received/sent message */ // char mtext[1]; /* text of the message */ // }; /* MESSAGE QUEUES EXAMPLE */ /*------------------------*/ #include #include #include #include #define MSG_KEY 1000 pthread_t threadid; void* MsgDSndThread(void* arg) { struct msgbuf *snd = (struct msgbuf *)malloc(16); key_t fd; snd->mtype = 1; strcpy(snd->mtext, "message"); fd = msgget(MSG_KEY, IPC_CREAT); msgsnd(fd, snd, 12, 0); free(snd); return 0; } void CreateThreadL() { pthread_create(&threadid,(pthread_attr_t *)NULL,MsgDSndThread, NULL); } int main() { struct msgbuf *rcv = (struct msgbuf*)malloc(16); key_t fd = msgget(MSG_KEY, IPC_CREAT); CreateThreadL(); msgrcv(fd, rcv, 6, 0, 0); msgctl(fd, IPC_RMID, NULL); free(rcv); return 0; } But while compiling showing some errors..... like test.c: In function 'MsgDSndThread': test.c:23: error: dereferencing pointer to incomplete type test.c:24: error: dereferencing pointer to incomplete type How to clear these errors... With regards KRISH+:cool:
-
Hiii.. I try to create message queue Inter process communication mechanism, a small program. Here is my code. // struct msgbuf // { // long int mtype; /* type of received/sent message */ // char mtext[1]; /* text of the message */ // }; /* MESSAGE QUEUES EXAMPLE */ /*------------------------*/ #include #include #include #include #define MSG_KEY 1000 pthread_t threadid; void* MsgDSndThread(void* arg) { struct msgbuf *snd = (struct msgbuf *)malloc(16); key_t fd; snd->mtype = 1; strcpy(snd->mtext, "message"); fd = msgget(MSG_KEY, IPC_CREAT); msgsnd(fd, snd, 12, 0); free(snd); return 0; } void CreateThreadL() { pthread_create(&threadid,(pthread_attr_t *)NULL,MsgDSndThread, NULL); } int main() { struct msgbuf *rcv = (struct msgbuf*)malloc(16); key_t fd = msgget(MSG_KEY, IPC_CREAT); CreateThreadL(); msgrcv(fd, rcv, 6, 0, 0); msgctl(fd, IPC_RMID, NULL); free(rcv); return 0; } But while compiling showing some errors..... like test.c: In function 'MsgDSndThread': test.c:23: error: dereferencing pointer to incomplete type test.c:24: error: dereferencing pointer to incomplete type How to clear these errors... With regards KRISH+:cool:
Are you using a commented-out type? :wtf:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hiii.. I try to create message queue Inter process communication mechanism, a small program. Here is my code. // struct msgbuf // { // long int mtype; /* type of received/sent message */ // char mtext[1]; /* text of the message */ // }; /* MESSAGE QUEUES EXAMPLE */ /*------------------------*/ #include #include #include #include #define MSG_KEY 1000 pthread_t threadid; void* MsgDSndThread(void* arg) { struct msgbuf *snd = (struct msgbuf *)malloc(16); key_t fd; snd->mtype = 1; strcpy(snd->mtext, "message"); fd = msgget(MSG_KEY, IPC_CREAT); msgsnd(fd, snd, 12, 0); free(snd); return 0; } void CreateThreadL() { pthread_create(&threadid,(pthread_attr_t *)NULL,MsgDSndThread, NULL); } int main() { struct msgbuf *rcv = (struct msgbuf*)malloc(16); key_t fd = msgget(MSG_KEY, IPC_CREAT); CreateThreadL(); msgrcv(fd, rcv, 6, 0, 0); msgctl(fd, IPC_RMID, NULL); free(rcv); return 0; } But while compiling showing some errors..... like test.c: In function 'MsgDSndThread': test.c:23: error: dereferencing pointer to incomplete type test.c:24: error: dereferencing pointer to incomplete type How to clear these errors... With regards KRISH+:cool:
Is that a serious question? The compiler didn't know what msgbuf* was because you've commented out the entire structure. How about you learn the very basics before attempting bigger things?
“Follow your bliss.” – Joseph Campbell
-
Hiii.. I try to create message queue Inter process communication mechanism, a small program. Here is my code. // struct msgbuf // { // long int mtype; /* type of received/sent message */ // char mtext[1]; /* text of the message */ // }; /* MESSAGE QUEUES EXAMPLE */ /*------------------------*/ #include #include #include #include #define MSG_KEY 1000 pthread_t threadid; void* MsgDSndThread(void* arg) { struct msgbuf *snd = (struct msgbuf *)malloc(16); key_t fd; snd->mtype = 1; strcpy(snd->mtext, "message"); fd = msgget(MSG_KEY, IPC_CREAT); msgsnd(fd, snd, 12, 0); free(snd); return 0; } void CreateThreadL() { pthread_create(&threadid,(pthread_attr_t *)NULL,MsgDSndThread, NULL); } int main() { struct msgbuf *rcv = (struct msgbuf*)malloc(16); key_t fd = msgget(MSG_KEY, IPC_CREAT); CreateThreadL(); msgrcv(fd, rcv, 6, 0, 0); msgctl(fd, IPC_RMID, NULL); free(rcv); return 0; } But while compiling showing some errors..... like test.c: In function 'MsgDSndThread': test.c:23: error: dereferencing pointer to incomplete type test.c:24: error: dereferencing pointer to incomplete type How to clear these errors... With regards KRISH+:cool:
Please point to the line #23 :) You could use your structure by instance (without malloc/free):
msgbuf mb = {0};
mb.mtype = 1;
...
msgsnd(.., &mb,..);
...Check your definition of Irrationality[^] :) 1 - Avicenna 5 - Hubbard 3 - Own definition
-
Are you using a commented-out type? :wtf:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]I can't understand the question?
-
Is that a serious question? The compiler didn't know what msgbuf* was because you've commented out the entire structure. How about you learn the very basics before attempting bigger things?
“Follow your bliss.” – Joseph Campbell
I think that structure is defined in #include
-
I think that structure is defined in #include
Do you think is there or are you sure that it is there? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hiii.. I try to create message queue Inter process communication mechanism, a small program. Here is my code. // struct msgbuf // { // long int mtype; /* type of received/sent message */ // char mtext[1]; /* text of the message */ // }; /* MESSAGE QUEUES EXAMPLE */ /*------------------------*/ #include #include #include #include #define MSG_KEY 1000 pthread_t threadid; void* MsgDSndThread(void* arg) { struct msgbuf *snd = (struct msgbuf *)malloc(16); key_t fd; snd->mtype = 1; strcpy(snd->mtext, "message"); fd = msgget(MSG_KEY, IPC_CREAT); msgsnd(fd, snd, 12, 0); free(snd); return 0; } void CreateThreadL() { pthread_create(&threadid,(pthread_attr_t *)NULL,MsgDSndThread, NULL); } int main() { struct msgbuf *rcv = (struct msgbuf*)malloc(16); key_t fd = msgget(MSG_KEY, IPC_CREAT); CreateThreadL(); msgrcv(fd, rcv, 6, 0, 0); msgctl(fd, IPC_RMID, NULL); free(rcv); return 0; } But while compiling showing some errors..... like test.c: In function 'MsgDSndThread': test.c:23: error: dereferencing pointer to incomplete type test.c:24: error: dereferencing pointer to incomplete type How to clear these errors... With regards KRISH+:cool:
I have got the solution for your problem. when you type cat /usr/include/sys/msg.h you can see that the struct is commented out when __USE_GNU is not defined. /usr/include/sys/msg.h:
#ifdef __USE_GNU
/* Template for struct to be used as argument for `msgsnd' and `msgrcv'. */
struct msgbuf
{
long int mtype; /* type of received/sent message */
char mtext[1]; /* text of the message */
};
#endifA bit of Googeling brings the result that you should
#define _GNU_SOURCE
to use that struct. It is important to define it before you#include <sys/msg.h>
. I hope i helped. greetings 0xeffe TLDR solution:#define _GNU_SOURCE
#include <sys/msg.h>