bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] include in a C++ program


From: Bruno Haible
Subject: Re: [bug-gnulib] include in a C++ program
Date: Tue, 12 Dec 2006 15:05:03 +0100
User-agent: KMail/1.9.1

Lorenzo Bettini wrote:
> I tried it and got no problem, but as far as I understand this is not a
> proof, since
> 
> #if defined HAVE_DECL_STRDUP && !HAVE_DECL_STRDUP && !defined strdup
> /* Duplicate S, returning an identical malloc'd string.  */
> extern char *strdup (const char *s);
> #endif
> 
> so the extern definition is not parsed, since it finds the definition of
> strdup in string.h (included in strdup.h).

Yes, the absence of a failure doesn't prove anything.

> However, I tried this test program:
> 
> #include <iostream>
> 
> extern char *strdup (const char *s);
> 
> int main()
> {
>   char *copy = strdup("foobar");
>   std::cout << copy << std::endl;
> 
>   return 0;
> }
> 
> and got no problem

This doesn't prove anything either: <iostream> may include <string.h>, which
may have an extern "C" declaration for strdup.

Can you tell us the list of .h files that you want to use from C++? It's
easier to make them C++ safe than to consider when exactly the extern "C"
will be needed or not.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]