Re: Array size depending on symbol address
- From: gordonb.lv833@xxxxxxxxxxx (Gordon Burditt)
- Date: Tue, 29 Nov 2005 20:36:29 -0000
>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
.
- Follow-Ups:
- Re: Array size depending on symbol address
- From: usenet
- Re: Array size depending on symbol address
- References:
- Array size depending on symbol address
- From: usenet
- Array size depending on symbol address
- Prev by Date: Re: sizeof a union
- Next by Date: Re: Array size depending on symbol address
- Previous by thread: Array size depending on symbol address
- Next by thread: Re: Array size depending on symbol address
- Index(es):
Relevant Pages
|