www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - convert *void to void[]

reply gabrielsylar <noreply email.com> writes:
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
next sibling parent reply TSalm <TSalm free.fr> writes:
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
parent TSalm <TSalm free.fr> writes:
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
prev sibling next sibling parent Robert Fraser <fraserofthenight gmail.com> writes:
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
prev sibling next sibling parent John C <johnch_atms hotmail.com> writes:
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
prev sibling next sibling parent gabrielsylar <noreply email.com> writes:
John C 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); }
return sqlite3_column_blob(stmt, n)[0 .. n];
int i=sqlite3_column_bytes(stmt, n); return sqlite3_column_blob(stmt, n)[0 .. i]; thanks, it works. and much simpler than i tought
May 06 2009
prev sibling parent reply downs <default_357-line yahoo.de> writes:
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
parent gabrielsylar <noreply email.com> writes:
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