[gdal-dev] constexpr - was Re: [gdal-commits] r41044 - trunk/gdal/port
Kurt Schwehr
schwehr at gmail.com
Sat Dec 16 06:33:45 PST 2017
A few points... All my personal opinions. Written on a phone, so sorry for
the bad writing
Writing happens once
Modifying happens occasionally
Debugging through and reading happen continuously throughout the community
GDAL is probably the largest source of oss fuzz bugs. I think we should be
doing more, not less, to make the system more stable and debugable.
Each individual change might not seen like much, but they really add up.
There is a lot I have to keep in my head for gdal that I don't with other
code bases because the are using the current conventions that help with so
many issues and give common ground.
Well done C++ makes being large scale systems so much easier and
modernizing GDAL means the whole community will get more out of GDAL.
These points are especially true with the sprawling style of GDAL.
Things like consexpr are easy and set us up for lower maintenance costs in
the future with C++14, 17 and beyond.
On Dec 16, 2017 1:27 AM, "Andrew C Aitchison" <andrew at aitchison.me.uk>
wrote:
> On Fri, 15 Dec 2017, Even Rouault wrote:
>
> Kurt,
>>
>> It doesn't look like constexpr is available in VS2013 (at least not in
>> all sub-versions of it):
>> https://stackoverflow.com/questions/20264644/constexpr-not-
>> compiling-in-vc2013
>>
>> Personnally, I don't see it as a super needed feature that would justify
>> dropping VS2013
>> support. Especially in the below use cases where it doesn't bring
>> anything more than const,
>> except more characters to type/read. I'd bet any sane compiler in -O2
>> will compile the source
>> to the same machine code in all those cases
>>
>
> As a C programmer, writing gdal device drivers is teaching me much about
> C++, but I'm finding it difficult to understand why I should need to care
> whether a const is a constexpr.
>
> Except in the rare case where I might want a value that cannot be
> initialised
> at compile time, but my code must not change once it has been initialised,
> I don't see the need to distinguish between the two and wish that a const
> was a constexpr unless otherwise declared.
>
> I worry that Kurt's improvements are turning C++ into a foreign language
> for me.
>
> On vendredi 15 décembre 2017 07:04:23 CET you wrote:
>>
>>> Author: goatbar
>>> Date: 2017-12-15 07:04:23 -0800 (Fri, 15 Dec 2017)
>>> New Revision: 41044
>>>
>>> Modified:
>>> trunk/gdal/port/cpl_conv.cpp
>>> Log:
>>> const -> constexpr for things known at compile time in cpl_conv.cpp
>>>
>>>
>>> Modified: trunk/gdal/port/cpl_conv.cpp
>>> ===================================================================
>>> --- trunk/gdal/port/cpl_conv.cpp 2017-12-15 14:37:43 UTC (rev
>>> 41043)
>>> +++ trunk/gdal/port/cpl_conv.cpp 2017-12-15 15:04:23 UTC (rev
>>> 41044)
>>> @@ -340,8 +340,8 @@
>>> /**********************************************************
>>> **************/
>>>
>>> // ASCII characters.
>>> -static const char knLF = 10;
>>> -static const char knCR = 13;
>>> +constexpr char knLF = 10;
>>> +constexpr char knCR = 13;
>>>
>>> /**
>>> * Reads in at most one less than nBufferSize characters from the fp
>>> @@ -666,7 +666,7 @@
>>> /* the line.
>>> */
>>> /* --------------------------------------------------------------------
>>> */
>>> char *pszRLBuffer = nullptr;
>>> - const size_t nChunkSize = 40;
>>> + constexpr size_t nChunkSize = 40;
>>> char szChunk[nChunkSize] = {};
>>> size_t nChunkBytesRead = 0;
>>> int nBufLength = 0;
>>> @@ -1984,8 +1984,8 @@
>>> /* CPLDMSToDec()
>>> */
>>> /**********************************************************
>>> **************/
>>>
>>> -static const char *sym = "NnEeSsWw";
>>> -static const double vm[] = { 1.0, 0.0166666666667, 0.00027777778 };
>>> +constexpr char sym[] = "NnEeSsWw";
>>> +constexpr double vm[] = { 1.0, 0.0166666666667, 0.00027777778 };
>>>
>>> /** CPLDMSToDec */
>>> double CPLDMSToDec( const char *is )
>>> @@ -2605,7 +2605,7 @@
>>> /* --------------------------------------------------------------------
>>> */
>>> /* Prepare buffer.
>>> */
>>> /* --------------------------------------------------------------------
>>> */
>>> - const size_t nBufferSize = 1024 * 1024;
>>> + constexpr size_t nBufferSize = 1024 * 1024;
>>> GByte *pabyBuffer = static_cast<GByte
>>> *>(VSI_MALLOC_VERBOSE(nBufferSize)); if( pabyBuffer == nullptr )
>>> {
>>>
>>> _______________________________________________
>>> gdal-commits mailing list
>>> gdal-commits at lists.osgeo.org
>>> https://lists.osgeo.org/mailman/listinfo/gdal-commits
>>>
>>
>>
>> --
>> Spatialys - Geospatial professional services
>> http://www.spatialys.com
>>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20171216/e7a08741/attachment-0001.html>
More information about the gdal-dev
mailing list