Declaring variables mid-function

Erik de Castro Lopo erikd@zip.com.au
Sat Dec 18 16:02:00 GMT 1999


Shawn wrote:
> 
>     I am writing a medium sized program, and ran into a problem where gcc
> would not compile any function that did not have all of its variables
> declared as the first lines of the function. 

This is one of the differences between C and C++. C++ allows variables
to be declared anywhere a statement could be declared while C insists
all variables be declared at the start of a block.

So, you have two options:

1) Compile your program with g++ (the GNU C++ compiler) instead of gcc.

2) Change your code to legal C.

Erik
-- 
+-------------------------------------------------+
     Erik de Castro Lopo     erikd@zip.com.au
+-------------------------------------------------+
"Anyone who says you can have a lot of widely dispersed people hack
 away on a complicated piece of code and avoid total anarchy has never
 managed a software project." - Andy Tanenbaum in 1992 on comp.os.minix


More information about the Gcc-help mailing list