cURL / Mailing Lists / curl-users / Single Mail


RE: Problem with strdup

From: David M. Bennett <>
Date: Sun, 19 Dec 2004 16:29:09 +1100

If I may insert by 2d worth---

The C/C++ standards do NOT define what will happen if you link together a
random mixture of libs from C/C++ and from different vendors. You can't rely
on it, and you shouldn't (if you value the stability of your product).

My scene is Windows (not *nix or Apple), but the same applies. I would never
consider linking together libs using C/C++ conventions from (say)

It is marginally safe to link C with C++, but only if you have total control
over all source, and you're prepared to track down and manage the inevitable
incompatibilities. If isn't strdup(), it will get in your printf(), fopen()
or somewhere else. Often the only solution is to convert the C code into C++
code -- I've been there.

Mixing different vendors is just as bad. Lots of stuff works; some doesn't;
don't risk it.

Solution: use final-linkage techniques. On Windows that usually means
building DLLs or COM objects. Different strokes for different folks.

Yes, it would be helpful if product suppliers delivered source code that
could be COMPILED as either C or C++, but expecting them to manage C++
problems in C code is not reasonable.

Happy to listen to other viewpoints, but that's the way I see it.


-----Original Message-----
[] On Behalf Of Daniel Stenberg
Sent: Sunday, 19 December 2004 9:23 AM
To: curl tool talk
Subject: Re: Problem with strdup

On Sat, 18 Dec 2004, Eric VERGNAUD wrote:

>> The strdup() function returns a pointer to a new string which
is a
>> duplicate of the string s. Memory for the new string is obtained
>> malloc(3), and can be freed with free(3).
> The problem is that Metrowerk's C library provides its own implementation
> malloc and free. I think this is because that C library is meant to
> and link under both MacOS 9 (which has no malloc) and MacOS X.

So it provides malloc and free but not strdup?

> Since libcurl is compiled using gcc, it links with apple's malloc and free

> while strdup internally calls Metrowerk's free (defined as _sys_free).

I get confused. Why does libcurl use Apple's malloc/free but Metrowerk's
strdup? The libc provided by Apple has a strdup too, surely?

      Daniel Stenberg -- --
       Dedicated custom curl help for hire:
Received on 2004-12-19