Error : Expecting ')' before '*' token? I really need help with this.
Discuss Error : Expecting ')' before '*' token? I really need help with this. in the C Programming forum on Dev Shed. Error : Expecting ')' before '*' token? I really need help with this. C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Posts: 4
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
__________________ 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
Posts: 4
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
#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?
Posts: 6,136
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.