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.orgMessage
Re: [AVR-Chat] Re: What does this error mean?
2005-02-22 by ethan@bufbotics.org
Attachments
- No local attachments were found for this message.