piclist 2008\07\28\095303a >
Thread: Starting with C
face picon face BY : Tamas Rudnai email (remove spam text)

> If you want its address to be constant across invocations of the function
> it is declared in, you just need to declare it static, but I'm sure you
> know that. So if this is what you want, this is what you need to do. This
> also means that even in a stack-based C implementation arr won't be on the
> stack anymore. (Typically... :)

That's true, however, a 'function lifetime' and a 'static' data has other
consumptions, which is the data stored in a 'static' variable should not be
overwritten at any time from outside of the function, therefore there will
be a dedicated RAM allocation to it.

The main problem is that C was never intended to have a non-reentrant
function / subroutine scheme, therefore all locals normally implemented as
stack based to be safe use. As Sergio mentioned many CPU has an indexed
indirect addressing mode so it is no problem in majority of cases, however,
PIC has got nothing like that. That's why all indirect addressing is
painful, whenever it is a stack variable, a pointer or an array in RAM or
ROM. That's why it is important to implement a very good opimalization to
every PIC C compiler that can determine:

1. Whenever a function is reentrant (by either using explicit pragma
declarations or implicit code analysis)
2. Whenever the variable / array can be statically addressed using overlayed
data area
3. Which functions or data can be overlapped - for this the program flow has
to be determined in a statical analysis way
(Note the statical anaysis can be very difficult if function pointers are in
use - aka computed goto)
4. Whenever a function can be expanded to spaghetti code to eliminate the
complication of using indirect addressing - therefore even if finction is
duplicated the overall code size and/or runtime speed can be reduced.


On Mon, Jul 28, 2008 at 1:45 PM, Gerhard Fiedler <TakeThisOuTlistsTakeThisOuTspamKILLspamconnectionbrazil.com
{Quote hidden}

> -
<492f1420807280652u78d92c8fm27849b54a5fbd574@mail.gmail.com> 7bit

In reply to: <1wjr6pxf9xoev$.dlg@connectionbrazil.com>
See also: www.piclist.com/techref/microchip/languages.htm?key=c
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Starting with C

month overview.

new search...