saaadhu / naggy

A live compiler diagnostics extension for Atmel Studio
18 stars 4 forks source link

Error when same loop variable is declared in more than one loop #27

Closed jerryGitHub closed 11 years ago

jerryGitHub commented 11 years ago

If you have the following program:

int main(void) { int sum = 0;

for (int i = 0; i < 10; i++)
    sum += i;

for (int i = 0; i < 20; i++)
    sum += i;
return 0;

} Naggy complains that i has been redefined, the Atmel Studio 6.1 compiler doesn't indicate an error. The scope of the variable i is confined to the loop, the name is invisible after the end of the first loop.

saaadhu commented 11 years ago

Does the Atmel Studio compiler command line have -std=gnu99 or -std=c99?

AFAIK, the scope restriction of the loop variable is a C99 feature. The released version of Naggy doesn't turn on C99 mode even if the Atmel Studio compiler settings does, but that's been fixed (see issue #6) and should work in the next release of Naggy.

jerryGitHub commented 11 years ago

You're right, the scope limitation seems to be a C99 feature. The standard setting in the Gnu-cc is -std=gnu99. If I remove this, then the same error as in Naggy appears. I'd looked up the scope in the New Testament, but it wasn't very clear to me on this point. Thanks for your quick reply, and for a very useful tool