2

I am having problems with assigning a value to cv. Based on my code below, I am getting error: invalid initializer at the line:

ChVec cv = r->cv;

Would anyone know what the issue might be?

Thanks for your help.

tuple.c

#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];

reln.h

#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
};
2

2 Answers 2

3

The type ChVec is an array, you can't initialize an array using another array (just like you can't assign to an array variable).

Instead you need to copy the array:

ChVec cv;
memcpy(cv, r->cv, sizeof cv);
Sign up to request clarification or add additional context in comments.

Comments

2

Arrays cannot be assigned the way you are doing.

You must use memcpy() to copy contents:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.