Article View: comp.lang.c.moderated
Article #2395Re: use of the break statement
From: Tanmoy Bhattacharya
Date: Wed, 27 Mar 1996 00:59
Date: Wed, 27 Mar 1996 00:59
53 lines
2744 bytes
2744 bytes
In article <4ijp75$19v@solutions.solon.com> Andrew Dalgleish <andrewd@axonet.com.au> writes: <snip> AD: Aren't these functionally identical? Yes, they are. Question is can you write a program that changes all uses of goto's to the corresponding structured blocks? AD: AD: do AD: statement; AD: while (exp); AD: AD: label: AD: statement; AD: if (exp) AD: goto label; AD: AD: If a compiler can't optimize this, I reserve the right to refuse AD: to trust it's optimizations on more complex constructs. Try the above problem, and you will see why the compiler may have trouble dealing with unstructured code. Let us take your example. In the structured form of a loop, a compiler can specifically check for expressions that are constants and pull them out of the loop. In the second form, it has to first check that no other statement branches to the label from anywhere (in which case it may or may not be expressible as a simple while loop), and only then make the determination of what are constants. In fact, loop optimizations are usually easier than control flow analyses that you need to optimize the latter. If I were designing a compiler, why should I spend time and effort writing complicated code to recognize a quintessentially bad programming construct? In this case, it turns out that the loop is easy to recognize, and many compilers will probably do so: but this is a very specific case. Why not say what you mean? That helps the person reading the code, and often helps the compiler. And, before you give your opinion as to what you trust and what you do not, please try to think of the poor compiler writer as well. Cheers Tanmoy -- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242) Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544 Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>, <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/ internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html> fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID:
<4ja3tl$pd6@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4hqedf$1m0@solutions.solon.com> <4i2k0n$8jd@solutions.solon.com> <4i97ht$8gb@solutions.solon.com> <4ianbt$h8m@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: tanmoy@qcd.Lanl.GOV (Tanmoy Bhattacharya) Newsgroups: comp.lang.c.moderated Subject: Re: use of the break statement Date: 26 Mar 1996 18:59:33 -0600 Organization: Los Alamos National Laboratory Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4ja3tl$pd6@solutions.solon.com> References: <4hqedf$1m0@solutions.solon.com> <4i2k0n$8jd@solutions.solon.com> <4i97ht$8gb@solutions.solon.com> <4ianbt$h8m@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com