Hi everyone,
I've been trying to code up a generic vector implementation in C, and the compiler has not been kind to me...
Here is the struct I have defined in a file "vector.h."
typedef struct
72 {
73 int elemSize;
74 int logLength;
75 int allocLength;
76 int delta;
77 void* elems;
78 VectorFreeFunction freefn;
79 }vector;
VectorFreeFunction is typedef-ed in vector.h
typedef void (*VectorFreeFunction)(void *elemAddr);
Now in "vector.c" the implementation file for the Vector, I have the following method.
void VectorNew(vector* v, int elemSize, VectorFreeFunction freeFn, int initialAllocation)
{
assert(elemSize > 0);
assert(initialAllocation >= 0);
v->elemSize = elemSize;
if(initialAllocation == 0)
initialAllocation = 10;
v->allocLength = initialAllocation;
v->delta = initialAllocation;
v->logLength = 0;
v->freefn = freeFn;
v->elems = malloc(v->allocLength * elemSize);
}
For some reason, gcc is giving me an error on the first line of this method telling me
expected ‘)’ before ‘*’ token
everytime I try to define a parameter as "vector* v".
What is it that I am doing wrong?