Go Down

Topic: Compiler Error C99 (Read 1 time) previous topic - next topic

megat

Hi, I'm new here. Someone can help me? I'm trying to include sd-reader.
I've got:
C:\arduino-0017\hardware\libraries\SdReader\fat.c:517: error: 'for' loop initial declaration used outside C99 mode
error.

Probably I've to switch compiler directive to gnu89 but I don't konw how do that.
I'm using Arduino Alpha IDE 0017
Thanks

PaulS

What this error means is that the code contains something like this:

Code: [Select]
for(int i=0; i<10; i++)
{
  // Do something
}

if(i == 10)
{
   // Do something
}


The "int i" in the for loop defines a variable, i, that is then used in the if test. The variable, i, went out of scope at the end of the for loop, since it was local to the for loop.

You don't need to change compiler directives. You need to change the code:

Code: [Select]
[glow]int i;[/glow]
for(i=0; i<10; i++)
{
  // Do something
}

if(i == 10)
{
   // Do something
}


Moving the variable declaration out of the for statement extends it's scope, and makes it available after the for loop ends.

Groove

#2
Feb 01, 2010, 02:49 pm Last Edit: Feb 01, 2010, 02:52 pm by GrooveFlotilla Reason: 1
@PaulS - that is not what the error message means:
Code: [Select]
for(int i=0; i<10; i++)
is valid iff "-std=c99" is a compiler option, but in pre-ISO 9899:1999 C it is not valid.

The error message is issued because the loop control "i" is declared within the loop itself.

In your example, the error issued would be " 'i' undeclared (first use in this function" on the "if" statement.
Per Arduino ad Astra

megat

Thanks at all, I know that the problem is the syntax of declaration of variables in for statement.
The code isn't mine, it's a library for sd card and is full of situation of this kind. I'd like to find a way to alter compiler directives. I've modified the Makefile hardware/core but don't works

westfw

Try renaming the fat.c to fat.cpp ...

Go Up