[zeromq-dev] why do czmq methods take a char* parameter and not const char*?

Lindley French lindleyf at gmail.com
Sat Mar 8 21:00:24 CET 2014


I'm going to come down on the side of const correctness. If applied
consistently and logically, it doesn't complicate anything; problems only
arise when it's done in half-measures. Forcing people to cast away
constness is arguably worse because they might do it in a case when they
really shouldn't.

At the very least, const should be applied to char* types whenever
possible. This can be done without applying it everywhere else if necessary.


On Sat, Mar 8, 2014 at 8:11 AM, Turkey Breast <turkeybreast at yahoo.com>wrote:

> Can you give an example where adding const would break a method for
> existing users?
>
>
>
>
>
> On Saturday, March 8, 2014 8:39 AM, Pieter Hintjens <ph at imatix.com> wrote:
> The lack of consts in the CZMQ API is my fault. I don't like consts in
> C development; they add complexity for little (in my experience)
> benefit.
>
> Changing CZMQ now would break existing applications. I'd actually like
> to remove consts where they are, to get consistency and make the APIs
> more simple.
>
> I'd just add the casts on top. It's in a wrapper and invisible to
> application code. Will that work?
>
>
> On Sat, Mar 8, 2014 at 4:55 AM, Turkey Breast <turkeybreast at yahoo.com>
> wrote:
> > Not all the methods are consistent. zsockopt and zstr use const char*
> while zsocket, zcert and zauth use char*.
> >
> >
> >
> >
> >
> > On , Turkey Breast <turkeybreast at yahoo.com> wrote:
> > Would you accept such a patch?
> >
> >
> >
> >
> >
> >
> > On , Turkey Breast <turkeybreast at yahoo.com> wrote:
> > My custom wrapper:
> >
> > https://github.com/darkwallet/czmqpp
> >
> > See this file:
> >
> > https://github.com/darkwallet/czmqpp/blob/master/src/authenticator.cpp
> >
> > I'm not even sure if what I'm doing is right. Does ZMQ modify those
> buffers at all? If so, why? Otherwise if they're just lacking const
> qualifiers, I'd rather not needlessly copy buffers. Would make sense to add
> them to czmq if possible.
> >
> >
> >
> >
> >
> >
> > On Saturday, March 8, 2014 2:56 AM, Turkey Breast <
> turkeybreast at yahoo.com> wrote:
> > I'm writing a c++ wrapper and this causes problems because a) string
> constants casting to char* is discouraged b) const char*
> std::string::c_str() needs a const_cast<char*> which is dodgy.
> >
> > Is there any chance to make some of these methods with const char*
> instead?
> >
> > _______________________________________________
> > zeromq-dev mailing list
> > zeromq-dev at lists.zeromq.org
> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> >
> > _______________________________________________
> > zeromq-dev mailing list
> > zeromq-dev at lists.zeromq.org
> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140308/45fd5c6e/attachment.htm>


More information about the zeromq-dev mailing list