Re: [GRASS-dev] Min. req. of programming language standard support, GRASS GIS 8

2021-02-01 Thread Markus Metz
A pity that Nicklas did not answer in this thread, see his answer in
https://lists.osgeo.org/pipermail/grass-dev/2021-February/094913.html

I have not studied the different C standards and the state of their
implementation in different compilers and their different versions in
depth, and thus appreciate very much the summary of Nicklas!

IIUC, Nicklas recommends to allow C11 standard features in GRASS C code,
with no need to change the current code base, and all compilers in all
supported platforms apparently support C11.

+1 from me, as long as all stock compilers on all supported platforms
support C11

Markus M


On Mon, Feb 1, 2021 at 8:56 AM Moritz Lennert 
wrote:
>
>
>
> Am 31. Januar 2021 22:15:53 MEZ schrieb Markus Metz <
markus.metz.gisw...@gmail.com>:
> >On Fri, Jan 29, 2021 at 11:19 PM Moritz Lennert <
> >mlenn...@club.worldonline.be> wrote:
> >>
> >>
> >>
> >> Am 29. Januar 2021 20:54:06 GMT+00:00 schrieb Markus Metz <
> >markus.metz.gisw...@gmail.com>:
> >> >Hi Huidae,
> >> >
> >> >On Thu, Jan 28, 2021 at 6:30 PM Huidae Cho  wrote:
> >> >>
> >> >> Markus,
> >> >>
> >> >> I think we have to think about what benefits it would bring to us by
> >> >modernizing C code. Probably, not much at all. Personally, I would
keep
> >it
> >> >as is because the minimum set of anything (e.g., ANSI C with no new
> >> >features) would probably be more portable, I believe. In other words,
> >what
> >> >are we missing from C99?
> >> >
> >> >as I mentioned, there is no need to modernize the GRASS C code. The
> >> >question is if we officially allow C99 features.
> >> >
> >> >For example a number of useful math-related functions and macros are
only
> >> >available with C99. See /usr/include/math.h on your system and search
for
> >> >C99. Also a number of features related to data types, particularly for
> >> >various int datatypes (stdint.h), become available with C99. And the
> >> >geographic lib in PROJ with src/geodesic.c wants C99. For new PROJ
> >> >versions, C99 is a requirement.
> >>
> >>
> >> If proj requires it, doesn't it automatically become a requirement for
> >GRASS as well ?
> >
> >No, because the code base of other libs might have completely different
> >compile requirements. A software can use functions and libs of other
> >software packages, but does not need to follow the compile standards of
> >those other software packages, because they are compiled independently.
> >
>
> Thanks for the clarification.
>
> In light of that I agree that we should choose the oldest standard
possible, unless we _really_ need something only present in a more recent
version.
>
> @those who want to use more recent standards: what are your reasons for
that ?
>
> Moritz
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] Min. req. of programming language standard support, GRASS GIS 8

2021-02-01 Thread Nicklas Larsson via grass-dev


> On 1 Feb 2021, at 08:56, Moritz Lennert  wrote:
> 
> Thanks for the clarification.
> 
> In light of that I agree that we should choose the oldest standard possible, 
> unless we _really_ need something only present in a more recent version.
> 
> @those who want to use more recent standards: what are your reasons for that ?
> 
> Moritz



The immediate reason for me bringing this issue up to the ml, was the question 
on whether to include the standard header  (introduced with C99) 
for using printf format specifier. Something that would simplify portability.

It is my general impression that the newer standards, apart from adding new 
features to the language, make it somewhat stricter (thus probably safer) and 
actually improves portability.

The portability issue from our point of view, I presume, is rather the degree 
of the compilers’ (and platforms’) support of the standards. On this field, 
there has been major progress since last time this was discussed (correct me if 
I’m mistaken) some 10 years ago and especially in the last couple of years.
In particular, MSVC is notoriously lagging in support for new C standards, with 
Visual Studio 2013 giving only partial support of C99 [1]. Wheras gcc added 
"substantially complete support” for C99 with GCC 4.5 [2] and for C11 as of 4.9 
[3].
Last year support for (required features of) C11 and C17 was added with Visual 
Studio 2019 version 16.8 [4]. Clang, being a relatively new contestant, 
supports most of latest standards [5].

As noted by Markus and Māris, present code base doesn’t conform to C89/C90. I 
might add the use of inline to the list of non-C89. Inlines is a feature added 
with C99 (although GNU has it as an extension to C89 [6]).
In light of this fact alone, I think it would be good to reconsider 
recommendations/directions on C standard requirements. I can hardly imagine 
someone take the time to back-port relevant code just for the sake of it. If 
C89 doesn’t cut it, then what will? It feels natural to then jump to the next 
standard, C99.

The crux of the matter is that changes from C99 to C11 aren't cumulative, but 
in practice (at least partly) made C11 more lax. Some features introduced as 
mandatory in C99 were made optional in C11. This is, I suppose, the reason for 
the still only partly supported C99 in msvc, whereas proper support of C11 and 
C17 was added.

On the other end of the line of standards, there is the C17, which doesn’t 
bring any news compared to C11, but is rather a bug fix for the former [7]. 
Code written for C11 will work in C17 mode and the other way around, but the 
actual compiled code depends on the compiler. In order not to potentially 
exclude max. C11 compatible compilers (e.g. 4.9 > GCC < 8.1), I’d say C11 
support is preferable to C17.

In short, there is a lot to take into consideration. For me, C11 (perhaps with 
mandatory feature support only) still seem to be the best candidate. What 
platforms, compilers being used for future development of GRASS do not meet 
that requirement?
I’d like to emphasise, setting new requirements for C code is first and 
foremost important for new or otherwise updated code. No need to “modernise” 
the whole code base.

Regarding C++. I don’t know to what extent existing code comply to any 
standard. I do know that at least PROJ, GEOS, GDAL adhere to C++11, which is a 
de facto standard in most open source projects. If we would set a requirement 
and I believe we should, C++11 should be the one at this date.


GRASS did not only survive but also evolved beautifully, through decades of 
tech changes, by making strategic moves forward at the right time. I agree with 
Māris that, in the end, this is a question for PSC.


Cheers,
Nicklas



[1] 
https://devblogs.microsoft.com/cppblog/c99-library-support-in-visual-studio-2013/
[2] https://gcc.gnu.org/c99status.html
[3] https://gcc.gnu.org/wiki/C11Status
[4] 
https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/
[5] https://clang.llvm.org/compatibility.html
[6] https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Inline.html
[7] https://gcc.gnu.org/legacy-ml/gcc-patches/2017-10/msg02121.html


___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev