Thread: error: expected specifier-qualifier-list before

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    12

    error: expected specifier-qualifier-list before

    I am trying to make two linked lists. My nodes are defined as follows:
    Code:
    typedef struct{
    char *message;
    int msglength;
    pthread_t sender;
    mail *next;
    }mail;
    
    typedef struct{
    pthread_t addr;
    char * reply;
    int * replylength;
    mail *head;
    sem_t mailavailable;
    sem_t replydone;
    mailbox *next;}
    mailbox;
    This is the error I get on compile.
    srr.c:16: error: expected specifier-qualifier-list before ‘mail’
    srr.c:26: error: expected specifier-qualifier-list before ‘mailbox’

    Any help as always will be greatly appreciated.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The problem is that your structs are unnamed. You need to give them names so you can refer to them within themselves, e.g.,
    Code:
    typedef struct mail {
        char *message;
        int msglength;
        pthread_t sender;
        struct mail *next;
    } mail;
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    12
    My thanks.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    12
    next question.

    mailbox *new=malloc(sizeof(mailbox));
    if(sem_init(new->mailavailable,0,0));

    The program segfaults in the sem_init()

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    >> mailbox *new=malloc(sizeof(mailbox));

    I wouldn't call any of your variables "new." While allowed in C it isn't very descriptive of what "new" is for. new is also the name of an allocator in C++. I think it's a common enough keyword for you to avoid naming things after it.

    >> if(sem_init(new->mailavailable,0,0));

    Well it could depend on what sem_int() does, but take note of your semi-colons.

    What you have is the equivalent of
    Code:
    if ( sem_int(new->mailavailable, 0, 0) )
       /** do nothing **/ ;
    {
       /** bad stuff **/
       /** improper accessing of "new" because things are executed always **/
    }
    By the way, no one will be able to tell you where things went wrong if you don't post the other function.
    Last edited by whiteflags; 03-01-2008 at 01:56 AM.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    12
    Sorry that was just bad formatting of my code when I pasted it in here. The colons and if statements are fine in my code. sem_init() is a system call so I really don't have any control on what happens in there. I have read the man pages and seem to be making the call correctly.

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    12
    EDIT Solved I was forgetting to malloc the sem pointers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM