Re: String[] pointer to void* and back

2014-09-19 Thread seany via Digitalmars-d-learn
On Thursday, 18 September 2014 at 22:16:48 UTC, Ali Çehreli wrote: If you are holding an address in a void*, you must make sure that the original object is still at that location when you attempt to access the object. Does that mean, that there is no way to make a global stack accessible

Re: String[] pointer to void* and back

2014-09-19 Thread Ali Çehreli via Digitalmars-d-learn
On 09/19/2014 05:14 AM, seany wrote: On Thursday, 18 September 2014 at 22:16:48 UTC, Ali Çehreli wrote: If you are holding an address in a void*, you must make sure that the original object is still at that location when you attempt to access the object. Does that mean, that there is no

Re: String[] pointer to void* and back

2014-09-19 Thread anonymous via Digitalmars-d-learn
On Friday, 19 September 2014 at 12:14:19 UTC, seany wrote: On Thursday, 18 September 2014 at 22:16:48 UTC, Ali Çehreli wrote: If you are holding an address in a void*, you must make sure that the original object is still at that location when you attempt to access the object. Does that

String[] pointer to void* and back

2014-09-18 Thread seany via Digitalmars-d-learn
Consider this snippet: import std.stdio; import std.conv; import core.vararg; void main() { string[] s = [aa, bb, cc]; string []* ss; void * v; ss = s; v = cast(void*)s; ss = cast(string[]*) v; s = *ss; writeln(s); } This fails, Stack

Re: String[] pointer to void* and back

2014-09-18 Thread seany via Digitalmars-d-learn
Found, it should have been v = cast(void*)ss; sorry.

Re: String[] pointer to void* and back

2014-09-18 Thread Ali Çehreli via Digitalmars-d-learn
On 09/18/2014 01:59 PM, seany wrote: string[] s = [aa, bb, cc]; string []* ss; void * v; ss = s; v = cast(void*)s; Not s, but its address should be assigned to v: v = cast(void*)s; Only then it will match its reverse operation: ss =

Re: String[] pointer to void* and back

2014-09-18 Thread seany via Digitalmars-d-learn
Yes, thank you, I corrected that. However, if this v is a member of a class, like import std.stdio; import std.conv; import core.vararg; struct S { void *v; } class C { S* sx = new S; void dothings() { string[] ss = [1, 2, 4]; string[] *s; void *vv; s =

Re: String[] pointer to void* and back

2014-09-18 Thread Ali Çehreli via Digitalmars-d-learn
On 09/18/2014 02:35 PM, seany wrote: struct S { void *v; } class C { S* sx = new S; void dothings() { string[] ss = [1, 2, 4]; Note that ss is a local variable of a druntime type equivalent of the following: struct D_Slice_of_strings_ { size_t

Re: String[] pointer to void* and back

2014-09-18 Thread seany via Digitalmars-d-learn
what if i needed to access many such runtime variables of many types, and did not want to create a member for each type?

Re: String[] pointer to void* and back

2014-09-18 Thread anonymous via Digitalmars-d-learn
On Thursday, 18 September 2014 at 21:35:50 UTC, seany wrote: Yes, thank you, I corrected that. However, if this v is a member of a class, like import std.stdio; import std.conv; import core.vararg; struct S { void *v; } class C { S* sx = new S; void dothings() {

Re: String[] pointer to void* and back

2014-09-18 Thread bearophile via Digitalmars-d-learn
anonymous: Here, the pointer to the stack escapes the function. Don't do that! Hopefully the D type system will be improved with scoping tracking management, to turn similar operations into compilation errors (as in Rust, but perhaps in a less refined way). Bye, bearophile

Re: String[] pointer to void* and back

2014-09-18 Thread Ali Çehreli via Digitalmars-d-learn
On 09/18/2014 02:52 PM, seany wrote: what if i needed to access many such runtime variables of many types, and did not want to create a member for each type? If you are holding an address in a void*, you must make sure that the original object is still at that location when you attempt to