curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: CURLOPT_WRITEFUNCTION issues - warning: curl_easy_setopt expects a curl_write_callback argument

From: Timothe Litt <>
Date: Fri, 21 Jan 2022 06:35:56 -0500

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:
> as per curl.h and is the same as the example code:
> 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.

Received on 2022-01-21