Some guidance on writing a Deimos C library interface

Johannes Pfau nospam at example.com
Fri Jul 13 23:02:49 PDT 2012


Am Sat, 14 Jul 2012 05:24:50 +0200
schrieb Jens Mueller <jens.k.mueller at gmx.de>:

> * const T* should be replaced with const(T)*

When it's a function parameter you could even make it const(T*):
void hello(const char *name);
--> extern(C) void hello(const(char*) name);

as the pointer itself is passed by value, there's no way it could be
modified by hello. DMD should be able to figure that out and treat
const(char)* exactly the same, but last time I checked it didn't.

> * How to deal with macros?
There are different solutions. Some people prefer to make those
templates, so the binding can be used as a .di file and doesn't need to
be compiled. Others just use functions and hope the optimizer will
inline it ;-)

> 
> Can we write a recipe like guide for writing a Deimos interface?
> 
> Jens




More information about the Digitalmars-d mailing list