Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
May 06, 2009 convert *void to void[] | ||||
---|---|---|---|---|
| ||||
can anybody please tell me how to properly convert from void* to void[] as the code below? void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); } |
May 06, 2009 Re: convert *void to void[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to gabrielsylar | Le Wed, 06 May 2009 10:17:47 +0200, gabrielsylar <noreply@email.com> a écrit:
> can anybody please tell me how to properly convert from void* to void[]
> as the code below?
>
> void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }
Something like could works :
return *( cast(void[]*) sqlite3_column_blob(stmt, n) ) ;
|
May 06, 2009 Re: convert *void to void[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to gabrielsylar | gabrielsylar wrote: > can anybody please tell me how to properly convert from void* to void[] > as the code below? > > void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); } void[] has a length, so you have to know the length. Assuming the length is n... Maybe try something like this (untested): struct DynArray { public void* ptr; public size_t length; public T[] toArray(T)() { return cast(T[]) cast(void*) (*this); } } void[] get_bytes(int n) { return DynArray(sqlite3_column_blob(stmt, n), n).toArray!(void); } |
May 06, 2009 Re: convert *void to void[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to TSalm | Le Wed, 06 May 2009 10:33:33 +0200, TSalm <TSalm@free.fr> a écrit:
> Le Wed, 06 May 2009 10:17:47 +0200, gabrielsylar <noreply@email.com> a écrit:
>
>> can anybody please tell me how to properly convert from void* to void[]
>> as the code below?
>>
>> void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }
>
> Something like could works :
> return *( cast(void[]*) sqlite3_column_blob(stmt, n) ) ;
>
Forget my example, it's wrong.
Sorry.
|
May 06, 2009 Re: convert *void to void[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to gabrielsylar | gabrielsylar Wrote:
> can anybody please tell me how to properly convert from void* to void[] as the code below?
>
> void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }
return sqlite3_column_blob(stmt, n)[0 .. n];
|
May 06, 2009 Re: convert *void to void[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to gabrielsylar | gabrielsylar wrote: > can anybody please tell me how to properly convert from void* to void[] as the code below? > > void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); } In unrelated matters: if you're writing a sqlite3 binding, take a look at tools.sqlite3. :) http://dsource.org/projects/scrapple/browser/trunk/tools/tools/sqlite3.d |
May 07, 2009 Re: convert *void to void[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to downs | downs Wrote:
> gabrielsylar wrote:
> > can anybody please tell me how to properly convert from void* to void[] as the code below?
> >
> > void[] get_bytes(int n) { return sqlite3_column_blob(stmt, n); }
>
> In unrelated matters: if you're writing a sqlite3 binding, take a look at tools.sqlite3. :)
>
> http://dsource.org/projects/scrapple/browser/trunk/tools/tools/sqlite3.d
thanks, but im writing my own simple wrapper around sqlite3.dll(so) dynamic loadable library
|
Copyright © 1999-2021 by the D Language Foundation