C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 10th, 2013, 03:51 PM
camelCase camelCase is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 camelCase User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 49 sec
Reputation 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;
}

Reply With Quote
  #2  
Old January 10th, 2013, 04:02 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,389 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 1 m 11 sec
Reputation Power: 4080
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

Reply With Quote
  #3  
Old January 10th, 2013, 04:08 PM
camelCase camelCase is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 camelCase User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 49 sec
Reputation Power: 0
Quote:
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!

Reply With Quote
  #4  
Old January 10th, 2013, 04:13 PM
ptr2void ptr2void is online now
I haz teh codez!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2003
Posts: 2,476 ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 6 h 47 m 31 sec
Reputation Power: 2194
Why are you including list.c in list.h?

c Code:
Original - c Code
  1. #include <stdlib.h>
  2. #include "list.c"
  3.  
__________________
I ♥ ManiacDan & requinix

This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!

Reply With Quote
  #5  
Old January 10th, 2013, 04:19 PM
camelCase camelCase is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 camelCase User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 49 sec
Reputation Power: 0
Quote:
Originally Posted by ptr2void
Why are you including list.c in list.h?

c Code:
Original - c Code
  1. #include <stdlib.h>
  2. #include "list.c"
  3.  


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?

Reply With Quote
  #6  
Old January 10th, 2013, 05:38 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,389 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 1 m 11 sec
Reputation Power: 4080
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.

Reply With Quote
  #7  
Old January 11th, 2013, 03:04 AM
camelCase camelCase is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 camelCase User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 49 sec
Reputation Power: 0
Quote:
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

Reply With Quote
  #8  
Old January 11th, 2013, 10:53 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,136 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 21 h 10 m 31 sec
Reputation Power: 1974
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Error : Expecting ')' before '*' token? I really need help with this.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap