interfacing with C: strings and byte vectors
yawniek via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 11 04:59:37 PDT 2016
On Saturday, 11 June 2016 at 10:26:17 UTC, Mike Parker wrote:
> On Saturday, 11 June 2016 at 09:32:54 UTC, yawniek wrote:
>
thanks mike for the in depth answer.
i forgot to add a few important points:
- the strings in vec_t are not c strings
- vec_t might contain other data than strings
the original ctor i pasted actually doesn't even work, temporarly
i solved it like
this(string s) {
char[] si = cast(char[]) s; //i'm scared
base = si.ptr;
len = si.length;
}
is there a better solution than to fearlessly cast away
immutability?
i guess i could just make a second vec_t that has immutable base
and length
that can be used in D to stay clean, would that be worth anything?
now what i still don't have a proper idea for is how can i create
wrappers for the
methods accepting vec_t in a clean way.
for the vec_t that are allocated in D-land we can state that the
C libs will not modify the data.
there is a lot of functions that accept vec_t.
is there no way to have strings auto cast to vec_t ?
another way i see is a UDA that generates the wrapper function(s).
other ideas?
More information about the Digitalmars-d-learn
mailing list