From romain at r-enthusiasts.com  Wed Oct  2 20:01:24 2013
From: romain at r-enthusiasts.com (Romain Francois)
Date: Wed, 02 Oct 2013 20:01:24 +0200
Subject: [Rd] C++ debugging help needed
In-Reply-To: <524C5BC3.1060204@gmail.com>
References: <524C32CF.2060307@gmail.com> <524C362F.1040108@gmail.com>
	<1380728746.1581.6.camel@braque.iarc.fr>
	<21068.16694.347218.948671@max.nulle.part>
	<524C5BC3.1060204@gmail.com>
Message-ID: <524C5F74.6080603@r-enthusiasts.com>

Duncan,

extern "C" just means that the function(s) below it have C calling 
conventions, so that .Call, .External, ... can find them. Without this, 
your function names would be c++ mangled to disambiguate different 
overloads.

What is inside can use namespace without any issue. You'd have something 
like:

extern "C" SEXP dot_call_function(){
     rgl::Whatever object(1, 2 ) ;
     object.do_something() ;
     return R_NilValue ;
}

IIRC, if you register your functions (see WRE #5.4), you don't need 
those extern "C" because you directly give the function pointer so you 
don't have to search for it with its name.

Romain

Le 02/10/13 19:45, Duncan Murdoch a ?crit :
> Thanks Dirk, Martyn and Romain.  I'm planning to do a temporary
> workaround release with the Shape class renamed to rglShape, but over
> the longer term I'll put everything that's supposed to be local inside
> an rgl namespace.  First I need to learn how namespaces interact with
> extern "C" declarations; pointers to any readable tutorials would be
> appreciated.
>
> Duncan Murdoch
>
> On 02/10/2013 11:52 AM, Dirk Eddelbuettel wrote:
>> On 2 October 2013 at 15:45, Martyn Plummer wrote:
>> | In C++, everything goes in the global namespace unless the programmer
>> | explicitly creates one. So when you dynamically load two dynamic shared
>> | libraries with a "Shape" object they clash.
>> |
>> | The solution here is to put
>> |
>> | namespace rgl {
>> | ...
>> | }
>> |
>> | around your class definitions in the rglm package, and
>> |
>> | using rgl::Shape
>>
>> Exactly.
>> | at the top of any source file that refers to rgl Shape. Likewise, the
>> | igraph package should declare shape in the "igraph" namespace.
>>
>> And as I wrote to Duncan off-list, igraph doesn't, even though it
>> otherwise
>> uses an igraph namespace:
>>
>>     /** Shape.h
>>      */
>>     #ifndef SHAPE_H
>>     #define SHAPE_H
>>     #include <string>
>>     #include "Color.h"
>>     #include "Ray.h"
>>     #include "Point.h"
>>     class Shape
>>     [....]
>>
>> So the clash is due to two packages simulatenously failing to make use of
>> namespaces.
>>
>> And at that point the linker appears to pick in search (link ?) order.
>>
>> Dirk

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30



[Rd] C++ debugging help needed
Romain Francois