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: bowman at montana dot com (bowman)
- Date: Sun, 19 Dec 1999 00:03:21 GMT
- Newsgroups: comp.os.linux.development.apps,gnu.gcc.help
- References: <385c11fa@oit.umass.edu> <5vhARpAQ5BX4EwUB@howgarth.demon.co.uk>
- Reply-To: bowman at montana dot com
- Xref: wodc7nx0 comp.os.linux.development.apps:8516 gnu.gcc.help:2239
Jamie Walker <jamie@sagaxis.co.uk> wrote:
>In standard C, you cannot declare variables part-way through any
>function.
I won't stick my neck out and say it is standard, as I don't have
Harbison & Steele handy, but gcc will accept declarations at the
head of any block. So
int foo()
{
int bar;
bar = 1234;
{
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.
Comments from the language lawyers are welcome on what exactly the standard
stipulates are welcome.