>
> *I'm not sure what you think is going on in that code. A while loop most
> certainly has a scope, in that the variables declared within the while
> block are not visible before nor after the loop. Any compiler that accepts
> the syntax (i.e. any modern C or C++ compiler) will treat that exactly the
> same as if the variables were declared at the top of the function, except
> that the name will only be visible within the loop.*


You are absolutely correct, and I do not know what the hell I was thinking.
Generally I always declare variables outside of loops, because I think it
is clearer. But what should have made it clear to me is that anything
inside of curly brackets is limited in scope to that set of brackets. You
do not even need a function or loop, etc to limit scope in this manner.




On Sun, Jan 3, 2016 at 2:06 AM, Rick Mann <rm...@latencyzero.com> wrote:

>
> > On Jan 2, 2016, at 06:57 , William Hermans <yyrk...@gmail.com> wrote:
> >
> > The ints and floats inside the loop are not a problem. Only one of each
> is allocated on the stack when the function is entered, and then they're
> assigned each time through the loop. Perfectly fine (and good practice for
> limiting the scope of variables).
> >
> > This would assume you know which compiler is being used, and you've
> actually disassembled the executable to see what the compiler does.
> Generally, it is a bad idea to assume you know what is happening. Because
> of this ambiguity, it is considered bad form.
> >
> > A while statement has no concept of scope. So main() has scope whether
> inside the while statement, or not.
>
> I'm not sure what you think is going on in that code. A while loop most
> certainly has a scope, in that the variables declared within the while
> block are not visible before nor after the loop. Any compiler that accepts
> the syntax (i.e. any modern C or C++ compiler) will treat that exactly the
> same as if the variables were declared at the top of the function, except
> that the name will only be visible within the loop.
>
> --
> Rick Mann
> rm...@latencyzero.com
>
>
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to the Google Groups
> "BeagleBoard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to beagleboard+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to