Re: Array size depending on symbol address



>>I am running my code on an embedded platform without OS. I have defined some
>>data in a section called .eeprom. The section is defined by the linker
>>script and starts at address zero. The symbol __eeprom_end is defined by the
>>linker script as well, and lies at the end of this section. The address of
>>__eeprom_end is thus equal to the number of bytes in the .eeprom section.
>>
>>My problem : I want to declare an array in .bss with the same size of this
>>section. My naive approch was :
>>
>> extern void *_eeprom;
>> char eeprom_shadow[(int)&_eeprom_end];
>>
>>This fails miserably, ofcourse : the compiler doesn't know the address of
>>__eeprom before the linker is done, so it can not declare the array.
>>
>>Is there a trick to allocate the memory for this array at compile time ? I'd
>>rather not use malloc() and friends, since I am working on a platform with a
>>very small amount of memory, and don't like using dynamic memory here.
>
> You have a fundamental chicken-or-the-egg problem here. A change
> in the size of the array can change the size of the code (because,
> for example, instructions can have short or long offsets), which
> can change the size of the .eeprom section, which can change the
> size of the array, which can change the size of the code AGAIN,
> which can change the size of the .eeprom section AGAIN, ad nauseum.
>
> Gordon L. Burditt

Hi Gordon,

Yes, this would be a problem if my the rest of my code would change anything
to the .eeprom section. This is not the case however, since I specifically
declare some variables with attributes to place them in the .eeprom section,
and no other data will go there. (The rest is in the usual places, .text,
..data, .bss)

--
:wq
^X^Cy^K^X^C^C^C^C
.



Relevant Pages

  • Re: Exporting variables in and out subroutines (F77)
    ... F77 doesn't have the kind of dynamic ... >>memory capabilities you seem to be looking for in your ... >>n as a parameter in program helpme and declare A to have ... a big array in the main program and only use part of it. ...
    (comp.lang.fortran)
  • Re: Array of Tpagecontrol?
    ... You can declare an array of TPageControl but you can't initialise it. ... references to the memory occupied by the objects at run time. ...
    (comp.lang.pascal.delphi.misc)
  • Struct with fixed-length array member - is it possible?
    ... int V1; ... THE SAME MEMORY LAYOUT as the C structure. ... and all data, including the array, should be placed in this block. ... There is no possibility in C# to declare a fixed-size array and to 'embed' ...
    (microsoft.public.dotnet.framework)
  • Re: reassigning value of a pointer
    ... > declare that and assign a value and then print it ok. ... memory with malloc/memset, ... I didn't want to use an array as I wanted to dynamically allocate ...
    (comp.lang.c)
  • Re: Array size depending on symbol address
    ... >I am running my code on an embedded platform without OS. ... >__eeprom before the linker is done, so it can not declare the array. ... >very small amount of memory, and don't like using dynamic memory here. ...
    (comp.lang.c)