This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Declaring variables mid-function



> {
> int fubar;
> for (fubar=0; fubar<bar; fubar++)
> printf("completely fooed\n");
> }
> }
>
> should compile. I believe that fubar is at least lexically visible to the
> end of the function, unlike some languages where the scope would be
strictly
> the block.
>

Nope - once you hit the enclosing "}", fubar's toast. In C, variables have
scope only at the level in which they have been declared; in this case
that's within the block, not to the end of the function.

B=



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]