1718 – obscure exit with error code 5

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1718 - obscure exit with error code 5
Summary: obscure exit with error code 5
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
Reported: 2007年12月09日 06:37 UTC by Adolf Mathias
Modified: 2015年06月09日 01:14 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Adolf Mathias 2007年12月09日 06:37:36 UTC
The attached solver for the "escape from zurg" riddle doesn't compile with versions 2.007 and 2.008 anymore. Instead (from within emacs compilation mode) I get "compilation exited abnormally with code 5".
Modifying the function writecrossing as follows
void writecrossing(const Entry *e)
{ foreach(v;toys)
 if(e.cross&v.mask) writef("%s(%d), ",v.name, v.time);
 auto h = e.goal?"escape":"return";
 writefln("%s; %d minutes left", h, e.timeleft);
}
solves the problem.
Here the version of the program that doesn't compile.
I've tried without success to produce a substantially shorter program that shows the same error. It seems to depend on the circumstances.
import std.stdio;
struct Toy {
 ulong mask;
 invariant(char)[] name;
 int time;
};
Toy[4] toys = [{1,"Buzz",5},{2,"Woody",10},{4,"Rex",20},{8,"Hamm",25}]; 
struct Entry {
 int timeleft;
 bool goal; // true means that here is the goal of the escape
 ulong cross, // masks of characters that have just crossed
	here, there;
};
ulong alltoys = (1<<toys.length)-1;
void writecrossing(const Entry *e)
{ foreach(v;toys)
 if(e.cross&v.mask) writef("%s(%d), ",v.name, v.time);
 writefln("%s; %d minutes left", e.goal?"escape":"return", e.timeleft);
}
Entry[64] stack;
Entry* p=&stack[0],q=&stack[1];
int solcnt = 0, timeoutcnt = 0, crosscnt = 0;
void cross()
{ ++crosscnt;
 q.goal = !p.goal; q.here = p.there | q.cross; q.there = p.here & ~q.cross;
 if(q.goal && q.here==alltoys) {
 writefln("\nSolution %d",++solcnt);
 foreach(e;stack[2..q+1-&stack[0]]) writecrossing(&e);
 } else {
 p = q; q++;
 foreach(k,v;toys) {
 if(p.here&v.mask) {
	q.cross = v.mask; q.timeleft = p.timeleft - v.time;
	if(q.timeleft<0) timeoutcnt++; else if(q.cross!=p.cross) cross();
	foreach(w;toys[k+1..length]) {
	 if(p.here&w.mask) {
	 q.cross = v.mask|w.mask;
	 if(w.time>v.time) q.timeleft = p.timeleft - w.time;
	 if(q.timeleft<0) timeoutcnt++; else if(q.cross!=p.cross) cross();
	 }
	}
 }
 }
 q = p; p--;
 }
}
int main ()
{ q.timeleft = 60;
 p.there = alltoys; p.here = 0; p.goal = true; q.cross = 0;
 cross();
 writef("\ncross() called %d times; timeout reached %d times", crosscnt, timeoutcnt);
 return 0;
}
Comment 1 Walter Bright 2008年02月16日 06:03:05 UTC
Fixed dmd 1.026 and 2.010


AltStyle によって変換されたページ (->オリジナル) /