Casting isn't the answer.  Read the error carefully.  You're returning a size_t (integer) from a function declared to return a function pointer.  The pointer is supposed to be to a function that returns a size_t.

multiplying 2 size_t variables results in a size_t, not a function pointer.

curl_write_callback declares a pointer to the callback function. Your function (as in the example) needs to be the actual function - I assumed that was obvious.  Sorry that I wasn't explicit.

So your callback wants to be a

typedef size_t (curl_write_callback_action)(char *buffer,
                                      size_t size,
                                      size_t nitems,
                                      void *outstream);

note the omitted "*" vs. the original.

Perhaps curl.h should include typedefs for the callback actions as well as for the pointers...


Timothe Litt
ACM Distinguished Engineer
--------------------------
This communication may not represent the ACM or my employer's views,
if any, on the matters discussed.

On 21-Jan-22 06:13, Gavin Henry via curl-library wrote:
It enables link-time optimizations.  The compiler/linker can see further into 
to the source, and detect errors not seen at the module level.

It's saying that your callback routine must be declared/typedefed as a 
"curl_write_callback".
Thanks Tim.

Which is actually:

https://curl.se/libcurl/c/getinmemory.html
as per curl.h and is the same as the example code:

https://curl.se/libcurl/c/getinmemory.html

so if I switch to:


static curl_write_callback curl_to_jansson_to_version(void *buffer, size_t size,
                                     size_t nmemb, json_t *json)
{


I get:

Incompatible integer to pointer conversion returning 'unsigned long'
from a function with result type 'curl_write_callback' (aka 'unsigned
long (*)(char *, unsigned long, unsigned long, void *)')

error: returning ‘size_t’ {aka ‘long unsigned int’} from a function
with return type ‘curl_write_callback’ {aka ‘long unsigned int
(*)(char *, long unsigned int,  long unsigned int,  void *)’} makes
pointer from integer without a cast [-Werror=int-conversion]
    43 |         return size * nmemb;
       |                ~~~~~^~~~~~~


so I'd need to cast that.


Gavin Henry.
https://sentrypeer.org

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html

Reply via email to