Reputation: 91
This piece of code is throwing up the error:
invalid operands to binary !=(have 'dataframe' {aka 'struct dataframe'} and 'void *'
if (new->bucket[i] != NULL) {
Yet I don't understand why this error is occuring, as I am attempting to assess whether the certain cell of my array is NULL or not.
My structs and the function that contains the error throwing code:
enum dfStatus {
EMPTY = 2, FULL, REMOVED
};
typedef struct dataframe {
void *key;
void *data;
enum dfStatus status;
} dataframe;
typedef struct assoc {
dataframe *bucket;
unsigned int buckCnt;
unsigned int totalCnt;
unsigned int multip;
unsigned int keysize;
} assoc;
assoc* _assoc_resize(assoc* a)
{
assoc *ass = a, *new;
int size = ass->buckCnt, i, multi = ass->multip * 2;
dataframe *df = ncalloc(size * 2, sizeof(dataframe));
for (i = 0; i < size * SCALEFACTOR; i++) {
df[i].status = EMPTY;
}
new = ncalloc(1, sizeof(assoc));
new->multip = 1;
new->bucket = df;
new->buckCnt = size * 2;
new->totalCnt = 0;
for (i = 0; i < size; i++) {
if (new->bucket[i] != NULL) {
new->bucket[i / multi] = ass->bucket[i];
}
}
new->totalCnt = ass->totalCnt;
new->multip = multi;
free(ass->bucket);
free(ass);
a = new;
return a;
}
Upvotes: 1
Views: 3523
Reputation: 301
NULL can be used only with pointers. Even if new->bucket
is pointer, when you use new->bucket[i]
it will return dataframe
not pointer. You can try using double pointers, instead of saving new->bucket as dataframe*
save it as dataframe**
so it won't be 'array' of dataframe
but 'array' of dataframe*
.
Upvotes: 1