Hi all, I have several const arrays of structures, of variable length. I would like to store them in contiguous space, to use them as separate arrays or as an unique single big array. Does exist in RealView C an "Keep variables in order" switch like in C166? Is there any other way to "group" several arrays of homogeneous entities into one single big array without defining it twice? Thank you for any comment/suggestion Bruno
#include <stdint.h> uint16_t var11; uint16_t var12; uint16_t var13; uint16_t var14; uint16_t var15; uint16_t var21; uint16_t var22; uint16_t var23; uint16_t var31; uint16_t var32; typedef struct { void *ptr; uint16_t size; uint16_t min; uint16_t max; uint16_t def; } Parameter_t; /* 3 arrays of same type, Parameter_t does it exist any "pragma" to force the compiler to allocate the following 3 arrays in contiguous space and in the same order? I need both: 3 arrays and a single big one containing all of them in the same order */ Parameter_t const Parlist1 [] = { {&var11, sizeof(var11), 0, 100, 20}, {&var12, sizeof(var12), 0, 100, 20}, {&var13, sizeof(var13), 0, 100, 20}, {&var14, sizeof(var14), 0, 100, 20}, {&var15, sizeof(var15), 0, 100, 20}, }; Parameter_t const Parlist2 [] = { {&var21, sizeof(var21), 0, 100, 20}, {&var22, sizeof(var22), 0, 100, 20}, {&var23, sizeof(var23), 0, 100, 20}, }; Parameter_t const Parlist3 [] = { {&var31, sizeof(var31), 0, 100, 20}, {&var32, sizeof(var32), 0, 100, 20}, }; /* one BIG array containing all the previous variables in the same order. ideally, having "labels" would just achieve the desired result: it would be possible to define pointers into some array elements */ Parameter_t const ParlistAll [] = { // ParListPtr1: Beginning of ParList1 {&var11, sizeof(var11), 0, 100, 20}, {&var12, sizeof(var12), 0, 100, 20}, {&var13, sizeof(var13), 0, 100, 20}, {&var14, sizeof(var14), 0, 100, 20}, {&var15, sizeof(var15), 0, 100, 20}, // ParListPtr2: Beginning of ParList2 {&var21, sizeof(var21), 0, 100, 20}, {&var22, sizeof(var22), 0, 100, 20}, {&var23, sizeof(var23), 0, 100, 20}, // ParListPtr3: Beginning of ParList3 {&var31, sizeof(var31), 0, 100, 20}, {&var32, sizeof(var32), 0, 100, 20}, };
Yes, I tried to use unions, but I can not use them because I don't know the length of each array.
You could try some preprocessor magic. I can't say more since I don't understand what exactly you are trying to achieve.
Regards, - mike