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:
> So in that case
>
>  for (int i = 0; i < x; i++) {
>        }
>  for( int j = 0; j < x; j++) {
>        }
>
>  would take no more room than
>
>  void func (void)
>  {
>  int i;
>
>  for ( i = 0; i < x; i++) {
>        }
>  for( i = 0; i < x; i++) {
>        }
>  }
>

I agree with what you're saying, but I think there's a condition you may
have omitted....


void func (void) {
{
    if (THIS_CONDITION_EVALUATES_TO_FALSE) {

        for (int i=0; i<x; i++) {
            for (int j=0; j<y; j++) {
            }
        }
    }
}

In the scenario described, you'd never push 'i' or 'j' onto the stack
unless the condition is true and the code executes.  I like to scope my
variables as close as possible to where they're needed, that way I won't
allocate memory that isn't going to be used.

And I definitely agree that a compiler should be smarter than me and it
should notice that I only use a variable as a loop index, and scope it
properly for me, but I don't know enough about compilers to say whether a
nice one like gcc does that or not.


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.