This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler

Hello everyone,

I work in a compiler c2000

I have the following problem:

I have the following table

const ushort abc_1 [16] = { ....... };

const ushort abc_2 [16] = { ....... };

const ushort abc_3 [16] = { ....... };

I would like to get a table const with the values ​​of distance between the addresses of the tables defined above

example:

const long prova[] = {
          &abc_2 -  &abc_1,                  
          &abc_3 -  &abc_2,
          ecc...
};

I can not

thanks

Dell'Acqua

  • Dell'Acqua,

    The addresses of the arrays are not resolved until link time, so that is why the compiler is having trouble with it.  There may be some fancy way to do this at compile time, but I don't know it (if it exists).  Instead, I would just compute the array values at runtime in your program.  This also means that your prova[] array cannot be const, but that should not be a problem.

    #define N_abc  10
    const ushort abc_1 [16] = { ....... };
    const ushort abc_2 [16] = { ....... };
    const ushort abc_3 [16] = { ....... };

    void main(void)
    {
       long prova[N_abs];
     
       prova[0] = abc_2 - abc_1;
       prova[1] = abc_3 - abc_2;
       prova[2] = abc_4 - abc_3;
        ...
    }

    You could make this more elegant by using a 2-D array for abc, rather than the naming convention abc_x.  What I mean here

       const ushort abc[0,16]={....};

    Then you can use a for(;;) loop to initilize the prova array, rather than having to explicitly list each array by name.  You'd have something like this:

       prova[i] = &abc[i+1,0] - &abc[i,0];

    I didn't test the syntax above, but I think you can work it out if I'm off with something.

    Of course, it occurs to me that if you use a 2-D array, the distance between each array is completely known, and equal to the length of each array in 16-bit words.  In your case, this would be 16.  So, if you do it this way, you don't even need to compute prova.

     

    Regards,

    David