cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: init in a different function

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 16 Mar 2006 13:28:15 -0800

On Thu, Mar 16, 2006 at 08:41:13PM +0100, Fredrik Gustafsson wrote:
> this code gives me segment fault (in short):
>
> int main()
> {
> CURL * curl;
> init_c(curl);
> return 0;
> }
>
> void init_c(CURL * curl)
> {
> curl = curl_easy_init();
> }
>
> I don't get it. If I put the line "curl = curl_easy_init()" in main() it
> works fine...

That code is wrong, but I'm a bit surprised this causes a segfault if this
is all there is. What it looks like you're trying to do is get init_c
to pass back a curl handle. You need to pass in the pointer to the CURL
pointer to do that, like this: init_c(&curl) and store the handle like:
  *curl = curl_easy_init();
and modify the init_c declaration to take CURL** curl.

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2006-03-16