Declaring variables mid-function
Brendan Murray
bpmurray@nospam.mediaone.net
Sat Dec 18 17:44:00 GMT 1999
> {
> 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=
More information about the Gcc-help
mailing list