Pages: [1]   Go Down
Author Topic: Compiler Error C99  (Read 768 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46215
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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:
[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.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2883
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@PaulS - that is not what the error message means:
Code:
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.
« Last Edit: February 01, 2010, 08:52:31 am by GrooveFlotilla » Logged

Per Arduino ad Astra

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6378
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: