Date: Tue, 21 Jan 1997 09:25:39 -0600 (CST) From: Adrian Oboroc To: djgpp AT delorie DOT com Subject: C & C++ variable definitions Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Michael Phelps wrote: >On Sat, 18 Jan 1997, Daniel Boyer wrote: > >> Ok, can somebody please tell me what is wrong with this line of code: >> >> for(char SIX = 'a'; SIX < '}'; SIX++) > >It looks like you're trying to declare a variable within the for >statement. Change the file extension to ".cc" and compile it with gxx to >use C++, which allows such constructs. I don't think C allows this >(though I could be wrong, and I know it _does_ allow declaring variables >within a "block"). No, Michael, you are right. ANSI C lets you define variables *only* in the beginning of a block, before all operators. IE, will be right: char SIX; for(SIX = 'a'; SIX < '}'; SIX++) { ... } But completly wrong (for ANSI C, not for C++): for(char SIX = 'a'; SIX < '}'; SIX++) { ... } But it's all right with something like: char SIX; for(char SIX = 'a'; SIX < '}'; SIX++) { ... } { int SEVEN; } because SEVEN was defined in a beginning of the block, limited with brackets, no metter, thet "for" statement is plased before. CU, AsH