Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
July 01, 2018 Dynamic arrays / ~= giving an exception... | ||||
---|---|---|---|---|
| ||||
I'm a bit puzzled because I think this is pretty straight forward but doesn't work...
struct mystruct {
myPtr* root;
opApply(...){
myPtr*[] childs;
childs ~= root;
...
}
}
foreach(node; mystruct(myRoot)){
...
}
It compiles but the line with ~= gives the nice "bing" under Windows and the application hangs...
What doesn't this work?
--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster
|
July 01, 2018 Re: Dynamic arrays / ~= giving an exception... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert M. Münch | On 2018-07-01 20:55:16 +0000, Robert M. Münch said: > I'm a bit puzzled because I think this is pretty straight forward but doesn't work... > > struct mystruct { > myPtr* root; > > opApply(...){ > myPtr*[] childs; > > childs ~= root; > ... > } > } > > foreach(node; mystruct(myRoot)){ > ... > } > > It compiles but the line with ~= gives the nice "bing" under Windows and the application hangs... > > What doesn't this work? One more thing, myPtr* is a pointer to a C struct. So I have: extern(C) { struct myPtr; alias myPtrRef = myPtr*; } -- Robert M. Münch http://www.saphirion.com smarter | better | faster |
July 01, 2018 Re: Dynamic arrays / ~= giving an exception... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert M. Münch | On Sunday, 1 July 2018 at 20:55:16 UTC, Robert M. Münch wrote:
> I'm a bit puzzled because I think this is pretty straight forward but doesn't work...
>
> struct mystruct {
> myPtr* root;
>
> opApply(...){
> myPtr*[] childs;
>
> childs ~= root;
> ...
> }
> }
>
> foreach(node; mystruct(myRoot)){
> ...
> }
>
> It compiles but the line with ~= gives the nice "bing" under Windows and the application hangs...
>
> What doesn't this work?
Could you maybe provide a compilable example?
|
July 01, 2018 Re: Dynamic arrays / ~= giving an exception... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cym13 | On 2018-07-01 21:05:43 +0000, Cym13 said: > On Sunday, 1 July 2018 at 20:55:16 UTC, Robert M. Münch wrote: >> I'm a bit puzzled because I think this is pretty straight forward but doesn't work... >> >> struct mystruct { >> myPtr* root; >> >> opApply(...){ >> myPtr*[] childs; >> >> childs ~= root; >> ... >> } >> } >> >> foreach(node; mystruct(myRoot)){ >> ... >> } >> >> It compiles but the line with ~= gives the nice "bing" under Windows and the application hangs... >> >> What doesn't this work? > > Could you maybe provide a compilable example? I would like but I can't condense it down to a useable case. What I found out is, if I use: auto childs_app = appender(&childs); childs_app ~= root; things work. Does this give a hint why the plain straight version doesn't work? Maybe missing copy semantics or so? Just wild guessing here... -- Robert M. Münch http://www.saphirion.com smarter | better | faster |
July 02, 2018 Re: Dynamic arrays / ~= giving an exception... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert M. Münch | On 7/1/18 4:55 PM, Robert M. Münch wrote:
> I'm a bit puzzled because I think this is pretty straight forward but doesn't work...
>
> struct mystruct {
> myPtr* root;
>
> opApply(...){
> myPtr*[] childs;
>
> childs ~= root;
> ...
> }
> }
>
> foreach(node; mystruct(myRoot)){
> ...
> }
>
> It compiles but the line with ~= gives the nice "bing" under Windows and the application hangs...
>
> What doesn't this work?
>
It should work. We need more context to try and help figure it out. Even if you can't post the entire program, maybe more context from mystruct.
In general:
T*[] arr;
arr ~= someTPtr;
should ALWAYS work. There is absolutely no postblits or dangling pointers happening at THIS point, and you are allocating an array to hold a pointer.
I suspect that your diagnosis of where the problem is happening is faulty.
-Steve
|
July 02, 2018 Re: Dynamic arrays / ~= giving an exception... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Monday, July 02, 2018 14:46:28 Steven Schveighoffer via Digitalmars-d- learn wrote:
> It should work. We need more context to try and help figure it out. Even if you can't post the entire program, maybe more context from mystruct.
If the program size is too large to show a good example, then I'd suggest using dustmite to reduce it. That can sometimes take a while, but it should then give us something where we have a chance of diagnosing the problem.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation