i have been doing some testing of my console display functions and i wrote something like the following:
for (int i=0, i<100, i++)
{
console_putDec(i);
}
when i compiled using djgpp, it said something like "initial for loop declaration outside of C99 mode" what is C99 mode and why cant i do such a for loop?
for loops in C/djgpp C99 mode?
RE:for loops in C/djgpp C99 mode?
I don't know what is C99 mode and I do not use DJGPP, but you "for" statement is wrong: The initialization part, the condition part and the increment part are separated by ';', not by commas ',': try this out:
for (int i=0; i<100; i++)
{
console_putDec(i);
}
It should work!
for (int i=0; i<100; i++)
{
console_putDec(i);
}
It should work!
RE:for loops in C/djgpp C99 mode?
C99 is the newest C standard which does allow for declarations to be outside of blocks (if applied to a for loop, for example). Allowing flexibility of this nature, similiar to C++ in fashion. C89/C90 did not allow for this. C99 has not been vastly implemented on many systems, it's best to simply put for in a new block and use it that way and conform to C89/C90. However, if you absolutely *MUST* use C99, you may need to send your compiler a flag to do so...gcc would need -std=c99, for example.
{
int i;
for(i = 0; i < 100 ; i++)
{
console_putDec(i);
}
}
{
int i;
for(i = 0; i < 100 ; i++)
{
console_putDec(i);
}
}
RE:for loops in C/djgpp C99 mode? thank you
thanks, putting the loop inside of a block with curly braces worked great!