This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Declaring variables mid-function
- To: help-gcc at gnu dot org
- Subject: Re: Declaring variables mid-function
- From: "Brendan Murray" <bpmurray at nospam dot mediaone dot net>
- Date: Sat, 18 Dec 1999 20:44:30 -0500
- Newsgroups: comp.os.linux.development.apps,gnu.gcc.help
- Organization: Road Runner
- References: <385c11fa@oit.umass.edu> <5vhARpAQ5BX4EwUB@howgarth.demon.co.uk> <dhV64.1216$QU1.6733@newsfeed.slurp.net>
- Reply-To: "Brendan Murray" <bpmurray at nospam dot mediaone dot net>
- Xref: wodc7nx0 comp.os.linux.development.apps:8523 gnu.gcc.help:2241
> {
> 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=