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

Switch to Threaded View
Zookeeper, mail # user - The problem of using c binding function


Copy link to this message
-
Re: The problem of using c binding function
Patrick Hunt 2013-10-14, 20:31
Likely because data in the second case is allocated on the stack,
which goes out of scope asa you exit the method.

Patrick

On Fri, Oct 11, 2013 at 7:08 PM, 吴腾飞 <[EMAIL PROTECTED]> wrote:
> Hi
>
>
>
> I using c client binding fuction zoo_aget,the passed data cause problem.
>
>
>
> ZOOAPI int zoo_aget(zhandle_t *zh,const char *path,int
> watch,data_completion_t completion,const void *data)
>
>
>
> 1.Using like this is ok:
>
>
>
> int ret = zoo_aget(zkhandle, path,0,DataCompletion,” zoo_aget”);
>
> DataCompletion:
>
> DataCompletion(int rc, const char *value, int value_len, const struct Stat
> *stat, const void *data)
>
> {
>
>   Cout<<data<<endl;//out put is :zoo_aget
>
> }
>
>
>
> 2.But this is no right:
>
> Char* data = “zoo_aget”;
>
> int ret = zoo_aget(zkhandle, path,0,DataCompletion, data);
>
> DataCompletion:
>
> DataCompletion(int rc, const char *value, int value_len, const struct Stat
> *stat, const void *data)
>
> {
>
>   Cout<<data<<endl;//out put is not zoo_aget
>
> }
>
>
>
> Why I in 2 can not got correct output?Using zoo_axxx,pass data also the same
> question.
>
>
>
> Thanks,
>
>
>
> Albert Wu.
>