AnsweredAssumed Answered

Declaring variables inside the for loop statement

Question asked by Hy Mai Employee on Apr 4, 2014
Latest reply on Apr 4, 2014 by Matthew Kendall

DEar CW,


Declaring variables inside the for loop statement:

 

for(uint8_t Chr = 0; Chr < ITEM_TEXT_LENGTH; Chr++)

 

Versus not:

 

uint8_t Chr;

for(Chr = 0; Chr < ITEM_TEXT_LENGTH; Chr++)

 

Declaring variables inside the for loop statement throws this error:

 

‘for’ loop initial declarations are only allowed in C99 mode

It certainly isn’t a problem to move the declarations outside of the for loop, but I’d like to have the option of using C99 or know where it is. Do you  know if there is a checkbox or command line switch for GCC somewhere?

 

Regards,

hy

Outcomes