Some guidance on writing a Deimos C library interface

Jens Mueller jens.k.mueller at gmx.de
Sun Jul 15 21:06:50 PDT 2012


Johannes Pfau wrote:
> 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.

Very true. But just to be on the safe side I think replacing it with
const(T)* is better.

> > * 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 ;-)

I see.

Jens


More information about the Digitalmars-d mailing list