error: expected specifier-qualifier-list before

This is a discussion on error: expected specifier-qualifier-list before within the C Programming forums, part of the General Programming Boards category; I am trying to make two linked lists. My nodes are defined as follows: Code: typedef struct{ char *message; int ...

  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
    22,264
    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;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,758
    >> 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, 06: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, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21