zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marios Hadjieleftheriou <mha...@gmail.com>
Subject Re: C API question
Date Wed, 31 Jul 2013 16:24:30 GMT
Hi Mohammad.

The parameter is a const void * (reading from right to left: a pointer
to a void that is const). Hence the data pointed to cannot be changed.

Moreover, it does not make sense to pass a void* const (right to left:
a const pointer to a void) as a function argument, because the pointer
itself ("data" in this case) is passed by value, hence it is
meaningless for it to be const or not.

In any case, in my callback function I tried to reinterpret_cast my
data to a non-const instance and the compiler complained that it needs
to be const. I cannot change my data.

On Wed, Jul 31, 2013 at 12:55 AM, Mohammad Shamma
<mohammadshamma@gmail.com> wrote:
> I think the const in this case would cause the pointer to be fixed. The
> data referred to by the pointer can still be updated.
> This is a similar question on stackoverflow:
> http://stackoverflow.com/questions/6407041/constant-pointer
> On Tue, Jul 30, 2013 at 7:06 PM, Marios Hadjieleftheriou
> <mhadji@gmail.com>wrote:
>> The string_completiion_t callback signature of the Zookeeper C API is:
>> typedef void(* string_completion_t)(int rc, const char *value, const void
>> *data)
>> That means that when the callback is called, the user provided data is
>> returned as a const void and cannot be modified by client code, which
>> kind of defeats the purpose of passing any data in the first place.
>> Is there any reason why this parameter needs to be const?
> --
> Mohammad Shamma

View raw message