Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: What does this error mean?

2005-02-22 by ethan@bufbotics.org

Robert Adsett said:
>       At 02:22 PM 2/22/05 -0500, ethan@bufbotics.org wrote:
>  >
>  >void func (void) {
>  >{
>  >     if (THIS_CONDITION_EVALUATES_TO_FALSE) {
>  >
>  >         for (int i=0; i             for (int j=0; j             }
>  >         }
>  >     }
>  >}
>
>
>  You are assuming the compiler generates different code for this case.
> Have
>  you verified that it does?  I would expect most compilers to generate the
>  same code in either case since a) it's probably faster and b) probably
> less
>  code room and c) has no effect on the worst case stack usage.
>


Hmm, yes, I am assuming the compiler generates different code depending
upon how the variables are scoped.  Haven't looked into it at all, in
fact, I wouldn't even know where to look to find out.  I guess the
question that comes to mind is "where does it end?"  If the compiler
chooses to allocate the memory for a loop variable, how far does the
compiler take it?  What if you've got a function that is defined but never
invoked.  Do all of the local variables from that function get defined? 
How far does it go?


Better question, how does one (me) find out what the compiler has done to
me?  I'm pretty new to microcontroller programming (used to webservers
with gigs & gigs of memory) and I quickly found out on an ATtiny26 project
that I've definitely got to pay more attention to memory usage than in the
past.  Even simple things like using 'unsigned char' rather than 'int' for
values that won't exceed 255.  That change alone saved me about 40% of the
memory on the tiny26.  Its a whole new (and exciting) world.

Ethan
www.bufbotics.org

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.