[Proj] Code style in Proj

Thomas Knudsen knudsen.thomas at gmail.com
Mon Apr 30 06:44:25 PDT 2018


I think line 116 in Kristian's revised version misses an "else": Gnu C, and
probably many other compilers, accepts "naked" compound statements, but I
do not think it is in accordance with the C89 standard

2018-04-30 15:00 GMT+02:00 Kristian Evers <kreve at sdfe.dk>:

> Kurt,
>
> I think it looks good. I tried compiling the code and again I had the
> problem with declarations like
>
> XY xy = {0.0, 0.0};
>
> I’ve fixed those in a fork of your gist. See revision 2 in [0] for a
> proposed solution that I think
> is in line with your ideas
>
> I like how you’ve separated includes from the standard library on the PROJ
> internal includes. On
> a related note (for those who don’t already know) I have recently
> introduced the proj_math.h
> header which is intended as a PROJ replacement of math.h. proj_math.h’s
> purpose in life is to
> make sure that we can use C99 math functions on systems where they are not
> available.
> proj_math.h includes math.h and defines functions such as isnan() and
> hypot(). This way they
> can be used as you would on a C99-compatible system as long as proj_math.h
> is included.
> See revision 3 in [0].
>
> Would you be willing to write up a simple style guide for PROJ based on
> the ideas you have presented in
> this thread?
>
> /Kristian
>
> [0] https://gist.github.com/kbevers/17ec703942646e401b28a0975b2877
> 1d/revisions
>
> On 24 Apr 2018, at 12:05, Mateusz Loskot <mateusz at loskot.net> wrote:
>
> 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
>
>
>
> _______________________________________________
> 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/20180430/9a438ee4/attachment.html>


More information about the Proj mailing list