Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: insufficient use of const complicates calling. #2466

Merged
merged 1 commit into from
Mar 26, 2017

Conversation

evoskuil
Copy link
Contributor

Solution: make methods that don't mutate members const.

There are probably more, these were just the obvious ones.

@c-rack c-rack merged commit 8cf64c2 into zeromq:master Mar 26, 2017
@bluca
Copy link
Member

bluca commented Mar 26, 2017

I'm a bit concerned by this ABI change, it might not be backward compatible. What's the concrete advantage of this?

@evoskuil
Copy link
Contributor Author

evoskuil commented Mar 26, 2017

It should always be backward compatible to pass a non-const (or const) pointer to a const pointer parameter. The value is that when passing a const parameter as non-const one must either:

  1. cast away the const (unsafe)
  2. make the parameter mutable (unsafe)
  3. make the method which makes the call non-const

The third option is the only safe option. To do the others requires making assumptions that directly contradict the explicit statement by the code that it is unsafe (i.e. the lack of a const qualifier). This choice complicates calling. since the non-const method then infects the entire code base of the caller, forcing const calls to become non-const. This then requires const members to become non-const. This then requires the non-const members to require critical sections in in thread safe classes and causes the API of a higher level library to create the same exact problem for its users, eventually infecting all interfaces of all dependent projects. As a result people generally settle at some point for unsafe code, via option 1 or 2. I decided it would be better to just fix the root cause when I was faced with this specific set of choices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants