cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Callback function gives crazy "size_t nmemb" value for simple http get operation (C++)

From: Richard Atterer <richard_at_2009.atterer.net>
Date: Tue, 7 Apr 2009 21:37:48 +0200

On Sun, Apr 05, 2009 at 10:12:40AM -0400, A. Craig West wrote:
> 2009/4/5 Phil Blundell <pb_at_reciva.com>:
> > You need to provide a wrapper function to interface between the C and
> > C++ worlds, or make Book::write_html be a static member function rather
> > than an object method.
>
> The easiest thing to do in C++ is to pass a pointer to a static
> method. It needs to have the correct prototype,

While this works just fine and I've been doing it myself for years, I have
always had a bad feeling about it. In fact, I've switched over to 'extern
"C"' wrapper functions which then call the appropriate non-static method.

The thing is that AFAIK if you call a function with C++ linkage (including
static method) from C code and that C code thinks it's calling another C
function, strictly speaking the result is undefined.

'extern "C"' wrappers are a bit awkward because you have to declare them
all as friends of your classes, but IMHO they are a cleaner solution.

Cheers,

  Richard

-- 
  __   _
  |_) /|  Richard Atterer     |  GnuPG key: 888354F7
  | \/¯|  http://atterer.net  |  08A9 7B7D 3D13 3EF2 3D25  D157 79E6 F6DC 8883 54F7
  ¯ '` ¯
Received on 2009-04-07