Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. create message queues

create message queues

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialdata-structureshelp
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    krish_kumar
    wrote on last edited by
    #1

    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:

    C E R 0 4 Replies Last reply
    0
    • K krish_kumar

      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:

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      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]

      K 1 Reply Last reply
      0
      • K krish_kumar

        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:

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        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

        K 1 Reply Last reply
        0
        • K krish_kumar

          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:

          E Offline
          E Offline
          Eugen Podsypalnikov
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C CPallini

            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]

            K Offline
            K Offline
            krish_kumar
            wrote on last edited by
            #5

            I can't understand the question?

            1 Reply Last reply
            0
            • R Rajesh R Subramanian

              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

              K Offline
              K Offline
              krish_kumar
              wrote on last edited by
              #6

              I think that structure is defined in #include

              C 1 Reply Last reply
              0
              • K krish_kumar

                I think that structure is defined in #include

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                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]

                1 Reply Last reply
                0
                • K krish_kumar

                  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:

                  0 Offline
                  0 Offline
                  0xeffe
                  wrote on last edited by
                  #8

                  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 */
                  };
                  #endif

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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups