extern(C++, ns)

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 3 07:59:11 PST 2016


On 1/3/2016 7:02 AM, Jacob Carlborg wrote:
> On 2016-01-03 06:40, Walter Bright wrote:
>
>> I do not understand what difficulty you are having with this.
>
> I think what Manu is finding difficult is that "extern(C++, ns)" creates a
> symbol at the D side. Which is kind of unexpected as no other for of "extern"
> works like that.

I originally implemented the feature as 'namespace ns'. But nobody liked that, 
as it would encourage people to use namespaces for non-C++ interfacing purposes.


> That also makes it impossible to use the same namespace in
> different file, which is very common in C++.

It is not at all impossible, any more than it is impossible to declare C names 
in multiple files. But you do have to follow C/C++'s "One Definition Rule" or 
you'll get link errors.


> I think that code like:
>
> int x;
> extern (C++, ns) { char x; }
>
> Is less common than the using the same namespace in different files. It's also
> not very practical to create bindings for a complete library in a single module,
> if the library is big.

I agree it is not very practical to put it all in one file. But it isn't any 
more necessary than putting all the C declarations in one file, for the same reason.



More information about the Digitalmars-d mailing list