Remove declaration-after-statement C warning
Arnaud Fontaine
arnaud at andesi.org
Wed Sep 11 23:09:19 PDT 2013
Mouse <mouse at Rodents-Montreal.ORG> writes:
>> The one bit I would like to have is declarations in for/while loops,
>> such as
>>
>> for (int i = 0; i < MAXSCREENS; i++)
>
> I wish I knew more about the spec. If that's equivalent to
>
> int i;
> for (i=0;i<MAXSCREENS;i++)
>
> then I don't like it any better. But if i goes out of scope at the end
> of the loop, then I rather like the idea. (Even then, though, I'm not
> sure I like the syntax, because it looks as though it is going to have
> horrible parsing ambiguities in the presence of comma operators or
> multiple variable declarations in the init portion.)
No, it's equivalent to something like:
{
int i;
for(i=0;i<MAXSCREENS;i++)
{
...
}
}
which means that 'i' has a block scope and will go out at the end of the
block in the example above. At least, this is my understanding.
--
Arnaud Fontaine
More information about the xorg-devel
mailing list