[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gnulib] include in a C++ program
From: |
Lorenzo Bettini |
Subject: |
Re: [bug-gnulib] include in a C++ program |
Date: |
Mon, 11 Dec 2006 23:13:17 +0100 |
User-agent: |
Icedove 1.5.0.8 (X11/20061128) |
Bruno Haible wrote:
> Lorenzo Bettini wrote:
>> I've just started using gnulib, and I have a doubt.
>> I've imported strdup and I'm using it in a C++ program.
>>
>> Now should I import strdup.h in the C++ program simply like this
>>
>> #include "strdup.h"
>>
>> Or should I wrap it as follows?
>>
>> extern "C" {
>> #include "strdup.h"
>> }
>
> Just do an
>
> #include "strdup.h"
>
> and report it to us if it leads to link errors. We are willing to put
> extern "C" markers in gnulib's header files, since it's only a small effort
> to do so.
>
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).
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 should guarantee that the extern "C" is not
required?
thanks in advance
Lorenzo
--
+-----------------------------------------------------+
| Lorenzo Bettini ICQ# lbetto, 16080134 |
| PhD in Computer Science, DSI, Univ. di Firenze |
| Florence - Italy (GNU/Linux User # 158233) |
| http://www.lorenzobettini.it |
| http://tronprog.blogspot.com BLOG |
| http://www.purplesucker.com Deep Purple Cover Band |
| http://www.gnu.org/software/src-highlite |
| http://www.gnu.org/software/gengetopt |
| http://www.gnu.org/software/gengen |
| http://doublecpp.sourceforge.net |
+-----------------------------------------------------+