digitalmars.D.learn - convert *void to void[]
- gabrielsylar <noreply email.com> May 06 2009
- TSalm <TSalm free.fr> May 06 2009
- TSalm <TSalm free.fr> May 06 2009
- Robert Fraser <fraserofthenight gmail.com> May 06 2009
- John C <johnch_atms hotmail.com> May 06 2009
- downs <default_357-line yahoo.de> May 06 2009
- gabrielsylar <noreply email.com> May 06 2009
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
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
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
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
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
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 06 2009
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
May 06 2009









TSalm <TSalm free.fr> 