[Proj] Code style in Proj

Kristian Evers kreve at sdfe.dk
Mon Apr 30 08:57:05 EST 2018


Thomas,

Actually this was part of Kurts original proposal. The else is not missing here as you can see from the original code [0].
The code passed my compiler just fine with all the C89 specific flags turned on (as mentioned in an earlier email in
this thread). So here it is just a block introduced to create a scope where declarations can be made more local to
where they are used. If that is prohibited according to the standard I don’t know. I don’t have other ways to test
standard compliance than to compile the code with C89 flags turned on. For a more thorough test we can create a
pull request with the proposed changes and see how the various compilers on Travis and AppVeyor fares.

/Kristian

[0] https://github.com/OSGeo/proj.4/blob/d0fefa4104d9b655d59e400cda616f0b4d407071/src/PJ_aeqd.c#L110-L126


On 30 Apr 2018, at 15:44, Thomas Knudsen <knudsen.thomas at gmail.com<mailto:knudsen.thomas at gmail.com>> wrote:

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<mailto: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/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

_______________________________________________
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/4b4b7ea1/attachment.htm 


More information about the Proj mailing list