[Proj] Code style in Proj
Thomas Knudsen
knudsen.thomas at gmail.com
Tue Apr 24 04:37:44 PDT 2018
Yes, exactly... declarations must be at top of scope in C, while C++ (seen
from a C perspective) inserts an implied do { ... } while (0); around the
actual scope of stray declarations. Thanks for clarifying that: My brain is
so C style hardwired that I didn't consider the case of declaring things
anywhere else than at top of scope.
2018-04-24 12:05 GMT+02:00 Mateusz Loskot <mateusz at loskot.net>:
> 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
> _______________________________________________
> Proj mailing list
> Proj at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/proj
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20180424/91030e6b/attachment.html>
More information about the Proj
mailing list