Reputation: 2342
I have a function named unpack
, and compiling the C++ code leads to a couple of errors. The code is below:
static void unpack(void *v, ekf_t *ekf, int n, int m) {
/* skip over n, m in data structure */
char *cptr = (char *) v;
cptr += 2 * sizeof(int);
double *dptr = (double *) cptr;
ekf->x = dptr;
dptr += n;
ekf->P = dptr;
dptr += n * n;
ekf->Q = dptr;
dptr += n * n;
ekf->R = dptr;
dptr += m * m;
ekf->G = dptr;
dptr += n * m;
ekf->F = dptr;
dptr += n * n;
ekf->H = dptr;
dptr += m * n;
ekf->Ht = dptr;
dptr += n * m;
ekf->Ft = dptr;
dptr += n * n;
ekf->Pp = dptr;
dptr += n * n;
ekf->fx = dptr;
dptr += n;
ekf->hx = dptr;
dptr += m;
ekf->tmp0 = dptr;
dptr += n * n;
ekf->tmp1 = dptr;
dptr += n * m;
ekf->tmp2 = dptr;
dptr += m * n;
ekf->tmp3 = dptr;
dptr += m * m;
ekf->tmp4 = dptr;
dptr += m * m;
ekf->tmp5 = dptr;
}
And I get these errors propagated over every line of the code:
.../src/ekf.c:203:12: error: assignment to expression with array type
ekf->x = dptr;
^
.../src/ekf.c:205:12: error: assignment to expression with array type
ekf->P = dptr;
It should be noted that the code unpack
was grabbed from a C library. I have tried using an extern
, but this does not seem to work too well. Now, when I make
the original repository (https://github.com/simondlevy/TinyEKF), it seems to compile without a problem. The compile command for TinyEKF, which contains and uses this code, is:
gcc -Wall -I. -I../../src -o gps_ekf gps_ekf.c ../../src/tiny_ekf.c -lm
This is found within /extras/c/
within the repository and certainly uses the unpack
function.
Upvotes: 0
Views: 145
Reputation: 16876
According to this, ekf.x
is of type double x[]
. You can't just assign to an array like ekf->x = dptr;
, as the error says. If you want to copy data from dptr
to ekf->x
, you can use memcpy
:
memcpy(&ekf->x, dptr, sizeof(ekf->x));
The same goes for all the other assignments, most of those fields are double
arrays.
Upvotes: 1