0

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.

7
  • Please provide the definition of class/struct ekf_t. Commented Mar 20, 2019 at 7:53
  • 2
    Just compile it as C, not C++ - you can still link it with your C++ code of course. Commented Mar 20, 2019 at 7:55
  • Ensure x and P type of the fields in ekf_t are pointer to double double * Commented Mar 20, 2019 at 7:59
  • All those members are arrays, and you can't assign to arrays. Pick up a good beginners' book. Commented Mar 20, 2019 at 8:00
  • Not a minimal reproducible example... Commented Mar 20, 2019 at 8:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Here is what I don't understand. If it works for the examples given in the repository, I am just recreating the entire same thing within my program. Shouldn't it work?
I believe that they would be arrays in the original code too, being assigned to a double. Which is why I'm confused.
Which example file is this happening in? It would be interesting to have a look.
if you look into /extras/c, there is a GPS example that uses this and doesn't spit out an error.
it compiles, now to check if it functions in the manner that we want it to.

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.