[zeromq-dev] Question about constness

Sebastian Lauwers sebastian.lauwers at gmail.com
Tue Jul 24 15:23:34 CEST 2012


On 24 July 2012 06:47, Ming Ji <finalguy at gmail.com> wrote:
> Hi all,

Hi there,

> I am new to ZeroMQ. I am actually not quite comfortable about the
> constness in the API.

You are not the only one. This has been discussed a few times already:

http://lists.zeromq.org/pipermail/zeromq-dev/2010-October/007392.html
http://lists.zeromq.org/pipermail/zeromq-dev/2011-May/011668.html
http://lists.zeromq.org/pipermail/zeromq-dev/2010-July/004435.html

> For example,
> size_t zmq_msg_size(const zmq_msg_t* msg);

Indeed, but it also requires all the underlying calls to be
const-compatible. This, in and of itself, is not really an issue, but
as noted in the threads cited above, is prone to breakage unless  done
in major revisions.

Checking the zeromq 3.2 RC [1], I see this still hasn't been
applied---I don't know what the project's policy would be regarding
"breaking" the 3.2 API after the first RC has been released.
Constness is used a handful of times in zmq.h.

> Any comments?

Personally, I've wrapped the zmq.hpp API with my own interface (the
project that contains this is LGPL and will be released around
September), and which adds a number of objects to the standard CPP API
(ZMQSendingSocket, ZMQReceivingSocket, ZMQPublisherSocket, etc), and
full const-correctness. I didn't feel the need to change the zeromq
API per se, but it certainly might make things easier/safer for
others.

If there is a demand for it, I could probably provide a patch for the
CPP API, or even share my interface, if asked.

Lastly, on a purely stylistic note, I prefer adding the const modifier
after the symbol it applies to. I would thus re-write your provided
example as:

size_t zmq_msg_size(zmq_msg_t const * msg);

[1]: https://github.com/zeromq/zeromq3-x/blob/master/include/zmq.h

PS: First post on mailing lists. Hip hip.
PPS: Moderators, I tried sending from my @googlemail address, which
obviously wasn't accepted by mailman. Apologies.



More information about the zeromq-dev mailing list