Dereferencing pointer to incomplete type

Source: Internet
Author: User
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 ----------------------------------------
      
     
    
   
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.