confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Confuse-devel] cant get the result after callback function


From: Martin Hedenfalk
Subject: Re: [Confuse-devel] cant get the result after callback function
Date: Tue, 21 Oct 2003 21:31:32 +0200

Hi,

Short answer:
*(char **)result = value;

Longer answer:
The void *result argument is a pointer to storage for the value. A void pointer is used so the same callback function type can be used for all sorts of options. For integers the void * must be casted to an int * (or actually a long int *). For a string (ie, a char *) it must be casted to a char **. For strings this is a pointer to a pointer.

If you assign a value to (char *)result, all that is changed is the pointer passed to the callback function. If you instead assign to *(char **)result, you assign to the string (character pointer) pointed to by the result pointer.

/martin

tisdagen den 21 oktober 2003 kl 19.09 skrev .:

Hi all.

A have a callback function that changes the result value. I have tried
some methods to return new result, but when i do cfg_getstr() i always
got NULL.

I tried:

1) (char*)result=value;

2) result=(char*)calloc(1,strlen(value)+1);
   strncpy(result,value,strlen(value));

3) static char *newstr;
   ...
   newstr=(char*)calloc(1,strlen(value)+1);
   strncpy(newstr,value,strlen(value));
   result=newstr;

How to store the string into *result pointer inside callback
function ?

--
Best regards,
 .                          mailto:address@hidden






reply via email to

[Prev in Thread] Current Thread [Next in Thread]