C-binding external array.

ciechowoj via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 10 10:04:56 PDT 2016


On Wednesday, 10 August 2016 at 15:07:52 UTC, Ali Çehreli wrote:
> On 08/10/2016 02:05 AM, ciechowoj wrote:
> Better with some mixin magic:
>
> mixin template CArray(string symbol, T) {
>     pragma(mangle, symbol) extern extern(C) __gshared
>     mixin ("T[0] _c" ~ symbol ~ ";");
>
>     @property
>     mixin ("T* " ~ symbol ~ "() { return _c" ~ symbol ~ ".ptr; 
> }");
> }
>
> mixin CArray!("tab", int);
>
> tab[42] = 42;
>

This is very tempting to use. The only thing that stops me from 
doing that is I am unsure if the 'property' tab behaves in all 
contexts the same way the standard array behaves.



More information about the Digitalmars-d-learn mailing list