On Tue, Feb 22, 2005 at 01:55:26PM -0500, Robert Adsett wrote:
>
> At 06:33 PM 2/22/05 +0000, kc9dag wrote:
> >I'm used to working on computers with large amounts of memory and
> >processor speed, so I natually used my standared for loop
> >declaration:
> >for(type var = constant; condition; var++){}
> >
> >is this going to cause me problems on the memory limited AVR? Should
> >I get in the habit of delairing my variable before hand (I was always
> >taught this was a bad thing on higher languages which have built in
> >memory management) when I program for the AVRs?
That is the right sort of question. The only way to answer it is to
study the code generated by your project for your target.
> First C doesn't have built in memory management (at least in the sense of
> C# and Java). However var is placed on the stack (in a compliant
> compiler). Whether it's declared at the top of the routine or in a later
> loop it still is placed on the stack and room must be reserved. The only
> case in which there is a space saving is if you run consecutive loops with
> differently named variables AND the compiler is smart enough to re-use the
> stack space (I suspect gcc is but I don't know). So in that case
I think the whole point of declaring variables inline in the newer C
specs is to hit the dumb compilers in the face with a wet mop by
defining the limited scope of the variable so that its space is
reusable.
Gcc can be quite agressive in reuse without having to be hit in the face
with a wet mop. Is good to remember "-O0" (minus oh zero) compile option
so that one's source code debugger doesn't jump all over the place and
named variables one is watching don't magically change after their last
use.
--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.Message
Re: [AVR-Chat] Re: What does this error mean?
2005-02-22 by David Kelly
Attachments
- No local attachments were found for this message.