[英]Invalid operands to binary != (have struct and void *)
This piece of code is throwing up the error:这段代码抛出了错误:
invalid operands to binary !=(have 'dataframe' {aka 'struct dataframe'} and 'void *'
二进制的无效操作数!=(有 'dataframe' {aka 'struct dataframe'} 和 '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.但是我不明白为什么会发生此错误,因为我正在尝试评估我的阵列的某个单元格是否为 NULL。
My structs and the function that contains the error throwing code:我的结构和包含错误抛出代码的 function :
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;
}
NULL can be used only with pointers. NULL 只能与指针一起使用。 Even if
new->bucket
is pointer, when you use new->bucket[i]
it will return dataframe
not pointer.即使
new->bucket
是指针,当您使用new->bucket[i]
时,它也会返回dataframe
而不是指针。 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*
.您可以尝试使用双指针,而不是将 new->bucket 保存为
dataframe*
将其保存为dataframe**
,这样它就不会是dataframe
的“数组”,而是dataframe*
的“数组”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.