Re: Array size depending on symbol address
- From: usenet@xxxxxxx
- Date: 29 Nov 2005 20:42:14 GMT
>>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
.
- References:
- Array size depending on symbol address
- From: usenet
- Re: Array size depending on symbol address
- From: Gordon Burditt
- Array size depending on symbol address
- Prev by Date: Re: Array size depending on symbol address
- Next by Date: Re: strtok() and EOL
- Previous by thread: Re: Array size depending on symbol address
- Next by thread: Re: Array size depending on symbol address
- Index(es):
Relevant Pages
|