I have a function used to create a new GQueue
GQueue* newGQueue(int n_ele, int ele_size) { GQueue* q = (GQueue*) malloc(sizeof(GQueue)); if(!q) return NULL; q->ptr = malloc(n_ele * ele_size); if(!(q->ptr)) { free(q); return NULL; } q->in = q->out = q->count = 0; q->size = n_ele; q->ele_size = ele_size; return q; }
I use it as follows:
volatile GQueue * kbdQueue = newGQueue(10, 1);
However, the following compilation error occurs on this line:
Error: initializer element not constant
Why is this happening? 10 and 1 are obviously constants that should not bother malloc , etc. The code is pre c99 C.
Only the -Wall flag.
thanks
source share