简体   繁体   English

二进制操作数无效!=(具有结构和 void *)

[英]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.

相关问题 二进制 + 的无效操作数(具有 'struct student' 和 'int') - invalid operands to binary + (have 'struct student' and 'int') 二进制*的操作数无效(有&#39;ab {aka struct a}&#39;和&#39;ab * {aka struct a *}&#39;) - Invalid operands to binary * (have ‘ab {aka struct a}’ and ‘ab * {aka struct a *}’) 错误:对二进制%无效的操作数(具有“结构分数*”和“结构分数*”) - error: invalid operands to binary % (have ‘struct Fraction *’ and ‘struct Fraction *’) 错误:二进制&lt;&lt;的无效操作数(具有“ struct str *”和“ int”) - error: invalid operands to binary << (have ‘struct str *’ and ‘int’) 将错误无效操作数编译为二进制 &amp;&amp;(具有 'int' 和 'pthread_t' {aka 'struct<anonymous> '})</anonymous> - Compiling error invalid operands to binary && (have 'int' and 'pthread_t' {aka 'struct <anonymous>'}) 二进制表达式的无效操作数(&#39;struct node&#39;和&#39;struct node&#39;) - invalid operands to binary expression ('struct node ' and 'struct node ') 无效的操作数为二进制%(具有float和float) - Invalid operands to binary % (have float and float) 无效的二进制操作数(具有float和float) - Invalid operands to binary (have float and float) 错误:二进制%的操作数无效(有&#39;double&#39;和&#39;double&#39;) - error: invalid operands to binary % (have 'double' and 'double') 无效的二进制操作数/(具有“ float *”和“ int”)? - invalid operands to binary / (have ‘float *’ and ‘int’)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM