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


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.



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