Hi everyone,
Need little help on this one. I have a utility on PC that generates some arrays for me, and I put those arrays on megaAVR's program memory. Now the number of elements of these arrays varies a lot. The size of these arrays could be quite large(10000 bytes) or small(5 bytes). Consider it random. I just put the C file which contains these arrays along with the other files and hit compile. The program takes care of everything. The program only knows the names of these arrays. It has no idea of how many elements are there in each array.
So for example to keep it short consider something like this.
const __flash uint8_t data_A[] = { 0xff,0xff,0xff,0xff }; const __flash uint8_t data_B[] = { 0xff,0xff,0xff,0xff,0xff }; const __flash uint8_t data_C[] = { 0xff,0xff,0xff }; const __flash uint8_t data_D[] = { 0xff,0xff,0xff,0xff,0xff,0xff }; const __flash uint8_t data_E[] = { 0xff,0xff };
Now normally I can find the address of first element and last element of these arrays. Using the sizeof operator. Like this :-
const __flash uint8_t *startAddress[5]; const __flash uint8_t *endAddress[5]; int main(void) { startAddress[0] = data_A; endAddress[0] = &data_A[sizeof(data_A)-1]; startAddress[1] = data_B; endAddress[1] = &data_B[sizeof(data_B)-1]; startAddress[2] = data_C; endAddress[2] = &data_C[sizeof(data_C)-1]; startAddress[3] = data_D; endAddress[3] = &data_D[sizeof(data_D)-1]; startAddress[4] = data_E; endAddress[4] = &data_E[sizeof(data_E)-1]; while(1); }
By knowing the first and last element address of each array I can do all sorts of operations on them.
Now this works okay but I want to find the end address's with a loop. Reason being if this can be done then it opens doors for me to do something even further.
const __flash uint8_t *startAddress[] = {data_A,data_B,data_C,data_D,data_E}; const __flash uint8_t *endAddress[sizeof(startAddress)/2]; int main(void) { for(uint8_t x=0; x < (sizeof(startAddress)/2); x++) { endAddress[x] = ??? // What can we write here so that endAddress contains the address's of last element of all the data arrays. } while (1); }
At this point the startAddress array contains the base address's of every array. Can I use this somehow to fill the endAddress's? I mean without using the array names here. If this can't be done let me know so I don't try to do something that is not possible.
Thanks.