From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fdb77,5f529c91be2ac930 X-Google-Attributes: gidfdb77,public X-Google-Thread: f43e6,899fc98b2883af4a X-Google-Attributes: gidf43e6,public X-Google-Thread: 11232c,59ec73856b699922 X-Google-Attributes: gid11232c,public X-Google-Thread: 1108a1,59ec73856b699922 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,583275b6950bf4e6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-19 22:54:17 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshosting.com!news-xfer1.atl.newshosting.com!140.99.99.194.MISMATCH!newsfeed1.easynews.com!easynews.com!easynews!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Newsgroups: comp.lang.java.advocacy,comp.object,comp.lang.ada,misc.misc,comp.software-eng From: The Ghost In The Machine Subject: Re: Quality systems (Was: Using Ada for device drivers? (Was: the Ada mandate, and why it collapsed and died)) References: <9fa75d42.0304230424.10612b1a@posting.google.com> <9fa75d42.0305091549.48b9c5d9@posting.google.com> <7507f79d.0305121629.5b8b7369@posting.google.com> <9fa75d42.0305130543.60381450@posting.google.com> <254c16a.0305140549.3a87281b@posting.google.com> <9fa75d42.0305141747.5680c577@posting.google.com> <254c16a.0305160425.3bb89749@posting.google.com> <1053091306.979352@master.nyc.kbcfp.com> <7vaddj8k3d.fsf@vlinux.voxelvision.no> <7v65o78gtv.fsf@vlinux.voxelvision.no> X-face: "i;@/WO(?;[KC9sW;wG/4@H[_VFFH4?QHJ#O(?m}7fQMrJ,]0THA'\|e-EPG_>56Mi}_RRhBS'a2}u_7jm)0_+'=$V#E2r4#IQE/d)yMv3_4@hl<)mA&*tDN/ User-Agent: slrn/0.9.7.4 (Linux) Message-ID: <5ddnp-a63.ln1@lexi2.athghost7038suus.net> Date: Tue, 20 May 2003 05:52:09 GMT NNTP-Posting-Host: 165.247.213.121 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1053409929 165.247.213.121 (Mon, 19 May 2003 22:52:09 PDT) NNTP-Posting-Date: Mon, 19 May 2003 22:52:09 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.java.advocacy:64229 comp.object:63729 comp.lang.ada:37548 misc.misc:14306 comp.software-eng:19309 Date: 2003-05-20T05:52:09+00:00 List-Id: In comp.lang.java.advocacy, Ole-Hjalmar Kristensen wrote on Mon, 19 May 2003 08:46:06 GMT <7v65o78gtv.fsf@vlinux.voxelvision.no>: > Hyman Rosen writes: > >> Ole-Hjalmar Kristensen wrote: >> > Hyman Rosen writes: >> >> for (i = c.begin(); i != c.end(); ++i) >> > Yes, provided you get your termination condition of the loop right. >> >> Huh? That's the termination condition, right there in the middle. >> When you loop over a container, you start at begin(), and quit at end(). >> > > A small typo, and the loop will probably not do what you want. Yes, I > know the probability is very low. Not that low. enum State { idle, started, running, waiting, done}; State state = idle; for(i=0;state=idle;i++) { /* ... */ } Spot The Bug. I don't know if Ada went the Pascal route or not ( ':=' for assignments, '=' for testing), but that's one way of mitigating this bug. (A for_each() construct in C++/STL is highly preferable anyway. for_each(c.begin(), c.end(), f) does the trick. It's a pity there's no equivalent to Java's declaration though: new AbstractClass() { public void concreteMethod() {...} } :-) ) > What stops someone from modifying i inside the loop? Nothing. It's either a bug or a feature depending on how one looks at it. (Usually, it's a bug.) > > Also, begin() and end() only applies to STL type containers, > not to plain arrays. for_each() can take plain arrays, although the coding style is different: int a[10]; for_each(a,a+sizeof(a)/sizeof(a[0]),f); where f is a _Function; the only requirement here is that f(p) make sense, where p is an int; this means f can either be an actual function with a single int argument, or a class overloading () with a single int argument. f(int&) would work as well, within certain limitations. If one's worried about it one can declare for_each((const int *) a, (const int *) a+sizeof(a)/sizeof(a[0]), f); which isn't the pretties of constructs. :-) > > The only thing I'm saying is that C/C++ has no equivalent > of the Ada for loop. The plain loop .... end loop is the > equivalent of the C for loop. > This is more or less correct, although for_each() comes somewhat close. However, for_each() has not been around that long -- maybe since the late 1990's. (C++ has been around since 1990, if not even earlier; I still remember cfront and this= assignments.) -- #191, ewill3@earthlink.net It's still legal to go .sigless.