www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - C headers to D for opaque data types

reply John Love-Jensen <love-jensen mchsi.com> writes:
Hi everyone,

Let's say I have these two functions in a C library:

extern void Foo(MagicPtr);
extern void Bar(MagicPtr, int, char*);

And these opaque structs in that same C library:

typedef void* MagicPtr;
extern MagicPtr HeapAllocator;
extern Magicptr ExtantAllocator;

Now when I convert the header to a D Programming Language interface, I'm 
doing this...

module funny.magic

struct __Magic { }
typedef __Magic* MagicPtr;
extern (C) Foo(MagicPtr);
extern (C) Bar(MagicPtr, int, char*);
extern (C) MagicPtr HeapAllocator; // Nope.
extern (C) MagicPtr ExtantAllocator; // Nope.

It appears that D is not using HeapAllocator and ExtantAllocator 
identifiers as linked in from the libMagic.lib, but rather is creating 
its own HeapAllocator and ExtantAllocator identifiers.

When linking, the HeapAllocator and ExtantAllocator are producing link 
warnings for duplicate symbols.


What is the correct way to specify the external linkage of those two 
identifiers in the C-to-D interface module?

Sep 10 2005
parent John Love-Jensen <love-jensen mchsi.com> writes:
I see how to do it, here:

Sep 10 2005