Date: Thu, 13 Mar 1997 13:09:46 +0200 (IST) From: Eli Zaretskii To: Beautiful Savior Lutheran Church cc: djgpp AT delorie DOT com Subject: Re: DJGPP inconsistencies? In-Reply-To: <5g7vah$be8@news.epcc.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On 13 Mar 1997, Beautiful Savior Lutheran Church wrote: > I have noticed a few inconsistencies with the DJGPP compiler over > other C compilers I use. > The first one is that the lines: > > for(int i=0; i<256; i++) > { someFunction(i); > } > > won't compile SOMETIMES (?!?!?!), yet the lines: > > int i; > for (i=0; i<256; i++) > { someFunction(i); > } > > works everytime...why? Please always post the relevant details. In this case, you should have explained what does ``won't compile'' mean. Did you get an error message? If so, please post this message and the command line you used to compile your code. It is very hard to guess what your problems are without that info. One possible reason might be that you put the first fragment on a file with .c extension. GCC treats such files as C programs, and you can't declare a variable inside a for loop in C. If that's a C++ program, call the file .cc or .cpp, and it will compile. Another possibility is that you use `i' outside the for loop, in which case GCC will say that a variable declared inside the for loop is not valid outside it, according the latest C++ draft standard. > > Also, I sometimes get random compiler "parse" errors when I include > the following code in a program: > > char *str; > if ( (str = getenv("DEM_PATH")) == NULL) { > printf("\"DEM_PATH\" environment variable not set\n"); > exit(1); > } > > Yet again...WHY? It depends on the surrounding context, I guess, because the fragment seems OK to me by itself. Again, please post the shortest complete function source that, when compiled, exhibits the problem, and also post the exact error message(s) printed by GCC.