http://d.puremagic.com/issues/show_bug.cgi?id=3847
Ellery Newcomer <ellery-newco...@utulsa.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ellery-newco...@utulsa.edu --- Comment #1 from Ellery Newcomer <ellery-newco...@utulsa.edu> 2010-02-23 18:39:12 PST --- (In reply to comment #0) > What does this D2 program print, and why? > > > import std.stdio; > > bool thirdElementIsThree(int[] a) { > return a.length >= 3 & a[2] == 3; > } > > void main() { > int[][] tests = [[6, 5, 4, 3, 2, 1], > [1, 2], > [1, 2, 3], > [1, 2, 3, 4 ], > [1]]; > int n = 0; > > try { > int i = 0; > while (true) { > if (thirdElementIsThree(tests[i++])) > n++; > } > } catch(Error e) { > // No more tests to process > } > > writeln(n); // prints? > } Ooh! Ooh! I know! it segfaults because the loop doesn't terminate and eventually test[i++] attempts to access memory not allocated to that process! We're talking about things that would happen in C, right? Personally, I prefer and,or, etc over &&,||, etc because they take less finger gymnastics to type. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------