[Proj] Code style in Proj

Kristian Evers kreve at sdfe.dk
Mon Apr 30 16:20:02 EST 2018



On 30 Apr 2018, at 21:45, Kurt Schwehr <schwehr at gmail.com<mailto:schwehr at gmail.com>> wrote:

Thanks for the proj_coord().  I meant to look that up, but got interrupted by a poopy diaper.

I would be happy to create a draft document for people to comment on.  It will be slow going as I only get little bits of time here and there for the next week.


Thanks. Please take your time - we are in no rush.

I do have to say that I don't like removing the math.h from the main file.   The cost is small and it frees you to refactor other headers without wide ranging changes each time.


So you like it better if both math.h and proj_math.h are included? math.h is not included that many places today already as it is included in projects.h.
I figured it would be better to just include proj_math.h as.a rule of thumb when needing math functions since it would ensure that the C99 math functions
are handled correctly. Apart from this special case I absolutely agree that it is a good idea to include headers for the functions you need. At the moment
most of the common standard library headers are included in projects.h and not in the files where they are needed. That should be changed when projects.h
is removed from the public API.


On Mon, Apr 30, 2018 at 6:00 AM, Kristian Evers <kreve at sdfe.dk<mailto:kreve at sdfe.dk>> wrote:
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/17ec703942646e401b28a0975b28771d/revisions

On 24 Apr 2018, at 12:05, Mateusz Loskot <mateusz at loskot.net<mailto:mateusz at loskot.net>> wrote:

On 24 April 2018 at 11:45, Thomas Knudsen <knudsen.thomas at gmail.com<mailto: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<http://mateusz.loskot.net/>
_______________________________________________
Proj mailing list
Proj at lists.maptools.org<mailto:Proj at lists.maptools.org>
http://lists.maptools.org/mailman/listinfo/proj


_______________________________________________
Proj mailing list
Proj at lists.maptools.org<mailto:Proj at lists.maptools.org>
http://lists.maptools.org/mailman/listinfo/proj



--
--
http://schwehr.org<http://schwehr.org/>
_______________________________________________
Proj mailing list
Proj at lists.maptools.org<mailto:Proj at lists.maptools.org>
http://lists.maptools.org/mailman/listinfo/proj

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/proj/attachments/20180430/e3e9e3e5/attachment.htm 


More information about the Proj mailing list