From mboxrd@z Thu Jan 1 00:00:00 1970 From: Erik de Castro Lopo To: help-gcc@gnu.org Subject: Re: Declaring variables mid-function Date: Sat, 18 Dec 1999 16:02:00 -0000 Message-id: <385C1A3C.41E235D1@zip.com.au> References: <385c11fa@oit.umass.edu> X-SW-Source: 1999-12/msg00266.html 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Erik de Castro Lopo To: help-gcc@gnu.org Subject: Re: Declaring variables mid-function Date: Fri, 31 Dec 1999 22:24:00 -0000 Message-ID: <385C1A3C.41E235D1@zip.com.au> References: <385c11fa@oit.umass.edu> X-SW-Source: 1999-12n/msg00266.html Message-ID: <19991231222400.Rd5MPl37lSDzFeYzeWnW20HJhPixW8ZvUPH-7jHGpxg@z> 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