Conversion from the following. Http://community.csdn.net/Expert/TopicView.asp? Id = 3669686 here is an example. The structure is not correctly defined because the macro is not defined, so the above error occurs during compilation. -------------------------------------- A: a part of my program always has a compilation error. I don't know how to modify it. Please give some tips:/* file: Private. C */# include
# Include
# Include
# Include
Int main (INT argc, char * argv []) {int queue_id; struct msgbuf * MSG; struct msgbuf * recv_msg; int RC; // create a message queue queue_id = msgget (ipc_private, ipc_creat | 0600); If (queue_id =-1) {perror ("Main: msgget"); exit (1);} printf ("Message Queue created, queue ID '% d '. /n ", queue_id); // create the message structure MSG = (struct msgbuf *) malloc (sizeof (struct msgbuf) + strlen (" Hello World ")); MSG-> mtype = 1; strcpy (MSG-> mtext, "H Ello world "); // send the message rc = msgsnd (queue_id, MSG, strlen (MSG-> mtext) + 1, 0); If (rc =-1) {perror ("Main: msgsnd"); exit (1) ;}free (MSG); printf ("message placed on the queue successfully. /n "); // receive message recv_msg = (struct msgbuf *) malloc (sizeof (struct msgbuf) + strlen (" Hello World "); rc = msgrcv (queue_id, recv_msg, strlen ("Hello World") + 1, 0, 0); If (rc =-1) {perror ("Main: msgrcv "); exit (1);} printf ("Msgrcv: Received message: mtype '% d'; mtext' % s'/N", recv_msg-> mtype, recv_msg-> mtext); Return 0 ;} 26 rows: MSG-> mtype = 1;: dereferencing pointer to incomplete type! How can this problem be solved? Solution: B: In # include
Add a sentence before that line, like this: # DEFINE _ use_gnu # include
In this way, the compilation will be OK. This is because, for some reason, the msgbuf structure is not defined, so this structure is not implemented during compilation. Open msg. h and you will know. A: Thank you. It is really a macro that has not been added. Thank you very much ----------------------------------------