Opened 6 years ago

Closed 5 years ago

#7209 closed defect (wontfix)

API: Seemingly-missing consts

Reported by: blarg Owned by: blarg
Priority: normal Milestone: closed_because_of_github_migration
Component: default Version: svn-trunk
Severity: normal Keywords: api
Cc: antonio

Description

In many places in the GDAL C++ API, it seems as if function parameters are missing const qualifiers. For example, http://www.gdal.org/gdal__alg_8h.html#a50caf4bc34703f0bcf515ecbe5061a0a is prototyped as if it modifies its argument papszOptions, but as far as I can tell it doesn't actually do so.

Is there some reason for this? If not, would changes be accepted to fix this? Should it be one giant patch or a series of smaller ones? Note that this would be a 100% backward-compatible API change.

At the moment I am using const_cast all over my application code, which is hideously ugly and potentially incorrect.

The other alternative would be to make copies of all of my data before passing it to GDAL APIs that have this problem, then free it after the GDAL API returns. While correct, this would be inefficient.

The only good solution would be for GDAL to promise it won't modify data that it doesn't actually modify, by saying 'const'.

Change History (5)

comment:1 by Even Rouault, 6 years ago

There are backwards implication in doing such changes. This should be discussed as a RFC, and probably for a GDAL 3.0 One of the issue is that in C, "char**" isn't implicitly cast to "const char* const *" whereas in C++ it is OK

Last edited 6 years ago by Jukka Rahkonen (previous) (diff)

comment:2 by Even Rouault, 6 years ago

Keywords: api added
Summary: Seemingly-missing constsAPI: Seemingly-missing consts

comment:3 by blarg, 6 years ago

I am only proposing to change C++ APIs. I am not proposing to change any C APIs. I'm sorry if that wasn't clear.

Specifically, if changing the C++ APIs without changing the C APIs requires use of const_cast inside GDAL, then I think we should do that. In that case, at least the ugly "const_cast"s would be a partially-hidden artifact of GDAL's current implementation, instead of a requirement for callers of GDAL's C++ API. One day when the C implementation was changed, they could be removed, without changing the C++ API.

comment:4 by antonio, 6 years ago

Cc: antonio added

comment:5 by Even Rouault, 5 years ago

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: assignedclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.

Note: See TracTickets for help on using tickets.