I’m trying to create a struct used in two .c source files to make a simple linked list structure. I thought it would save time to create a struct in the header file, however, I get a ‘parse error before *’ error.
This is the code I’m using:
/*
* Structures.h
*
* Created on: Dec 17, 2011
* Author: timgreene
*/
#ifndef STRUCTURES_H_
#define STRUCTURES_H_
typedef struct list_struct {
int data;
struct list_struct* next;
struct list_struct* prev;
} list;
#endif /* STRUCTURES_H_ */
Edit: I did originally omit a detail that is, I’m actually compiling with xcc from the XMOS toolchain. I still don’t understand that there would be a difference in .h file syntax.
Could it be a compilation flag I’m using?
Here’s the console printout:
xcc -O0 -g -Wall -c -MMD -MP -MF"filter.d" -MT"filter.d filter.o " -target=XC-1A -o filter.o "../filter.xc"
In file included from ../filter.xc:15:
Structures.h:13: error: parse error before '*' token
Structures.h:14: error: parse error before '*' token
Structures.h:15: error: parse error before '}' token
Looking around in some of the XMOS documentation, it seems the problem is that XC is not C, it’s just a C-like language. From the “XC Programming Guide”:
…which explains why it doesn’t accept the
nextandprevpointers in your structure.Apparently xcc lets you mix C and XC sources, though, so if you were to limit your use of the structure to C code it should work. From the “XCC Command-Line Manual”, it appears that anything with a
.xcextension (as in the command line you used above) is treated as XC, rather than C, source code by default. This can be overridden by placing the option-xcbefore the C sources on the command line and-xafterward (or just rename the files with a.cextension).If you must use XC rather than C, you may need to find another way of doing things (arrays, maybe?).