Home > database >  How can use __attribute__ (section) for each element of an array?
How can use __attribute__ (section) for each element of an array?

Time:02-03

I have a multidimensional array and I want to define each element of this array in a different section. Something like:

int array [2][200];

array[0] __attribute__((section (".section1")));
array[1] __attribute__((section (".section2")));

I know this piece of code is not correct because __atribute__ ((section "section name")) should be used in the array definition. Do you have any suggestions on how I can do it?

Thanks in advance

CodePudding user response:

No. The array is a contigous chunk of memory and elements cannot be in different sections.

C standard (6.2.5.20):

An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type.

Do you have any suggestions on how I can do it?

You need to have two separate arrays in different sections and array of two pointers referencing those arrays.

  •  Tags:  
  • cgcc
  • Related