Array indexing starting at a number not 0

后端 未结 13 2367
Happy的楠姐
Happy的楠姐 2021-02-20 04:02

Is it possible to start an array at an index not zero...I.E. you have an array a[35], of 35 elements, now I want to index at say starting 100, so the numbers would be a[100], a[

13条回答
  •  旧巷少年郎
    2021-02-20 04:49

    Perhaps you can use union?

    #pragma pack(0)
    union 
    {
      char array[15000];
      struct { char sram[10000]; char bram[5000];  } map;
    } combination;
    

    They are physically contiguous. If you access 'array' then it will go into either bram or sram based on the offset

    You need the pragma to tell the compiler to NOT align struct members on word boundaries. This prevents a number of bytes of space between the two parts of the map structure.

提交回复
热议问题