Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
Zookeeper, mail # user - C API question


+
Marios Hadjieleftheriou 2013-07-31, 02:06
+
Mohammad Shamma 2013-07-31, 04:55
Copy link to this message
-
Re: C API question
Marios Hadjieleftheriou 2013-07-31, 16:24
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
<[EMAIL PROTECTED]> 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
> <[EMAIL PROTECTED]>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
+
Marshall McMullen 2013-07-31, 17:25
+
Marshall McMullen 2013-07-31, 17:31
+
Marios Hadjieleftheriou 2013-08-01, 15:14
+
Stephen Tyree 2013-08-01, 15:20