[Proj] Code style in Proj

Mateusz Loskot mateusz at loskot.net
Tue Apr 24 05:05:53 EST 2018


On 24 April 2018 at 11:45, Thomas Knudsen <knudsen.thomas at gmail.com> wrote:
>> In C too, but since C99.
>
> AFAIK this only applies to the "for (int i = 0;  i < n; i++)" syntax.
>
> while (...) {
>     int i = 123, j = 345;
>     k = i + j;
> }
>
> has been correct (and imho, preferable) syntax since K&R C

AFAIK, it's about compound statement.
C89 requires declaration at the top of blocks, while C99 lifts that:

$ cat test.c
int main()
{
    int i = 0;
    while (i < 10)
    {
        int j = 345;
        i = i + j;
    }

    {
        int z = 0;
        z = 1;
    }
    int x = 1;
}

$ gcc -std=c89 -pedantic test.c
test.c: In function ‘main’:
test.c:14:5: warning: ISO C90 forbids mixed declarations and code
[-Wdeclaration-after-statement]
     int x = 1;
     ^~~

$ gcc -std=c99 -pedantic test.c
$


Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net


More information about the Proj mailing list