www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Dynamic arrays / ~= giving an exception...

reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
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
Jul 01 2018
next sibling parent =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
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
Jul 01 2018
prev sibling next sibling parent reply Cym13 <cpicard openmailbox.org> writes:
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?
Jul 01 2018
parent =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
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
Jul 01 2018
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
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
Jul 02 2018
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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
Jul 02 2018