#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Error : Expecting ')' before '*' token? I really need help with this.[SOLVED]


    After many years of working with other languages, I have decided to bit the bullet and try to learn C. This is my first post on this forum, so Apologies if I have broken any rules or missed any etiquette rules here.

    Anyways. I have pasted my code below (Actual code is longer, but I have also tried to compile an exact copy of the code which is shortened to the same as this, and still get the error!

    Command used : gcc test.c -o test
    Error...

    In file included from list.h

    list.c:6:27: error: expected ')' before '*' token

    Code is pasted below, and I would REALLY appreciate any help I can get.

    I have already tried renaming the files, and changinf the ifndef and define names too, just incase they clash with something on my system. Resulted in the same output.

    ------------------
    list.h
    ------------------
    Code:
    #ifndef LIST_H
    #define LIST_H
    
    #include <stdlib.h>
    #include "list.c"
    /* Struct for linked list elements. */
    typedef struct listElement_
    {
        void                        *data;
        struct listElement_         *next;
    }listElement;
    
    /* Struct for link-list data structure */
    typedef struct linkedList_
    {
        int         size;
        int         (*match)(const void *key1, const void *key2);
        void        (*destroy)(void *data);
    
        /* The two elements below define the two elements
         * which must be known for a standard linked list */
        listElement *head;
        listElement *tail;
    }linkedList;
    
    void list_init(linkedList *list, void (*destroy)(void *data));
    
    #endif
    -------------
    list.c
    -------------
    Code:
    #include <stdlib.h>
    #include <string.h>
    
    #include "list.h"
    
    void list_init(linkedList *list, void (*destroy)(void *data))
    {
        list->size = 0;
        list->destroy = destroy;
        list->head = NULL;
        list->tail = NULL;
    
        return;
    }
    --------------------
    test.c
    --------------------
    Code:
    #include <stdio.h>
    #include "list.h"
    
    
    int main()
    {
        return 0;
    }
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    You have a missing semicolon in list.h
    Code:
    void list_init(linkedList *list, void (*destroy)(void *data));
    
    #endif
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by Scorpions4ever
    You have a missing semicolon in list.h
    Code:
    void list_init(linkedList *list, void (*destroy)(void *data));
    
    #endif
    Thanks, but unfortunately that didn't fix it :(

    I have added the ';' to the .h file, and updated the forum post.

    Is there anything else that stands out to you there?

    Thanks again!
  6. #4
  7. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,547
    Rep Power
    2337
    Why are you including list.c in list.h?

    c Code:
    #include <stdlib.h>
    #include "list.c"
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by ptr2void
    Why are you including list.c in list.h?

    c Code:
    #include <stdlib.h>
    #include "list.c"
    Because, if I don't... and I try to compile, I get a different error :

    undefined reference to `list_init'

    I know the above file means it can't see the function list_init... and since the main program includes the .h file, I was thinking the .h file needed to include the .c file, in order to see the functionality. no?
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    I took out the #include "list.c" line out from list.h and it compiled successfully:
    Code:
    gcc -Wall -o test test.c list.c

    Comments on this post

    • camelCase agrees : Thanks for your help.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by Scorpions4ever
    I took out the #include "list.c" line out from list.h and it compiled successfully:
    Code:
    gcc -Wall -o test test.c list.c
    Thankyou!, I think my issue here may have been that I wasn't adding list.c to my gcc command? Would that be the issue here?

    Thanks again
  14. #8
  15. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Think about it and you can answer your own question.

    In order to use a function in list.c, gcc needed to compile list.c and link in its object file. In order to compile list.c, gcc needed to know about list.c. The only way for gcc to know about list.c is for you to tell it. The way that you tell gcc about list.c is to include it in the command that invokes gcc.

    When you encounter situations like this, go through a similar thought process to answer your own questions.

IMN logo majestic logo threadwatch logo seochat tools logo