This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Arrays in contiguous space

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},
};

Parents
  • This is *EXACTLY* what I've been searching for!
    I already arrived by myself to this solution with #define PARLIST macros, but I missed the final 8 lines, and I wasn't able to figure out how to proceed.
    I knew I will find a solution asking the KEIL forum and I thank all of you for your support.
    Ciao. Bruno

Reply
  • This is *EXACTLY* what I've been searching for!
    I already arrived by myself to this solution with #define PARLIST macros, but I missed the final 8 lines, and I wasn't able to figure out how to proceed.
    I knew I will find a solution asking the KEIL forum and I thank all of you for your support.
    Ciao. Bruno

Children
No data