无效的初始化程序-结构数组

射手

我在给赋值时遇到问题cv根据下面的代码,我明白error: invalid initializer了:

ChVec cv = r->cv;

有人知道这个问题可能是什么吗?

谢谢你的帮助。

元组

#include "defs.h"
#include "tuple.h"
#include "reln.h"
#include "hash.h"
#include "chvec.h"
#include "bits.h"

Bits tupleHash(Reln r, Tuple t)
{
    ChVec cv = r->cv;
    ...
    ...
}

chvec.h

#include "defs.h"
#include "reln.h"

#define MAXCHVEC 32

typedef struct {
    Byte att;
    Byte bit;
} ChVecItem;

typedef ChVecItem ChVec[MAXCHVEC];

ln

#ifndef RELN_H
#define RELN_H 1

typedef struct RelnRep *Reln;

#include "defs.h"
#include "tuple.h"
#include "chvec.h"
#include "page.h"


struct RelnRep {
    Count  nattrs; // number of attributes
    Count  depth;  // depth of main data file
    Offset sp;     // split pointer
    Count  npages; // number of main data pages
    Count  ntups;  // total number of tuples
    ChVec  cv;     // choice vector
    char   mode;   // open for read/write
    FILE  *info;   // handle on info file
    FILE  *data;   // handle on data file
    FILE  *ovflow; // handle on ovflow file
};
一些程序员哥们

该类型ChVec是一个数组,您不能使用另一个数组初始化一个数组(就像您不能分配给数组变量一样)。

相反,您需要复制数组:

ChVec cv;
memcpy(cv, r->cv, sizeof cv);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章