Opened 15 years ago

Closed 6 years ago

#3127 closed defect (wontfix)

Use 'char const**' instead of 'char**' for input strings with pointer reset

Reported by: dougrm Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: unspecified
Severity: normal Keywords:


gdal-1.6.2/ogr Lots of input-only char*'s (with an input/output pointer to the char*) are declared char. The intent would be more clear and it would get rid of lots of casts to instead declare them char const. (The string chars cannot be changed, but the pointer to the first char in the string can.) The final cast used in the .cpp versions to reset the dereferenced inputs must also be removed. For instance, in ogr_geometry.h:
virtual OGRErr importFromWkt( char ppszInput ) = 0;
should be:
virtual OGRErr importFromWkt( char const
ppszInput ) = 0;
and in ogr_srsnode.cpp
OGRErr OGR_SRSNode::importFromWkt( char ppszInput ) has near the end:

*ppszInput = (char *) pszInput;

but should (with the above const), just have:

*ppszInput = pszInput;

Users can then also get rid of (char) casts on inputs. For example:
s = (char)&"some input string";
char const
s = &"some input string";
or for the brave just:
a.importFromWkt(&"some input string");
instead of the current:
a.importFromWkt((char)&"some input string");

To find examples of the problem do:
cd ogr
grep -i '\(import\|create\).*char \*\*' *.h

Change History (3)

comment:1 by warmerdam, 15 years ago

I am not interested in const correctness changes to the existing C or C++ API. In my experience the churn is not worth the supposed benefit in correctness. It would be desirable to be vigilant in this regard with new interfaces.

comment:2 by Jukka Rahkonen, 9 years ago

To be closed as wontfix because nobody wants to do that much work with fixing something that ain't really broken, or what?

comment:3 by Jukka Rahkonen, 6 years ago

Resolution: wontfix
Status: newclosed

No activity, closing.

Note: See TracTickets for help on using tickets.