Article View: comp.std.c++
Article #2487Re: New treatment of 'for (int i ...'
From: Robert Buren
Date: Thu, 09 Nov 1995 19:25
Date: Thu, 09 Nov 1995 19:25
53 lines
1993 bytes
1993 bytes
Steven Correll wrote:
|>
|> What was the rationale for this change, which from here looks quite
|> gratuitous? It's reminiscent of the old Pascal rule that the value of a
|> loop index was undefined after the loop exited; that was apparently
|> motivated by the belief that compilers were too stupid to figure out
|> on a case-by-case when a value could safely be killed.
|>
|> The change makes it difficult to write programs that will work in both old
|> compilers and new ones while implementors scurry to catch up with the
|> ever-inventive committee. This technique won't work in current compilers:
|>
|> for (unsigned i = 0; ...; ...)
|> ...
|> for (i = 0; ...; ...)
|> ...
|>
|> And this won't work in older ones:
|>
|> for (unsigned i = 0; ...; ...)
|> ...
|> for (unsigned i = 0; ...; ...)
|> ...
|>
|> Must portable programs do this?
|>
|> for (unsigned i0 = 0; ...; ...)
|> ...
|> for (unsigned i1 = 0; ...; ...)
|> ...
If you really want to write programs for both old and new compilers, what's
wrong with the following?:
{
unsigned i;
for( i = 0; ...; ...)
...
for( i = 0; ...; ...)
...
}
/Robert
--
Robert Buren
erarobu@era-t.ericsson.se
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<30A1F1F9.167EB0E7@era-t.ericsson.se>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<47itjt$65m@lhc.nlm.nih.gov> <sjcDHqMKM.MBG@netcom.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: Robert Buren <erarobu@era-t.ericsson.se> Newsgroups: comp.std.c++ Subject: Re: New treatment of 'for (int i ...' Date: 09 Nov 1995 19:25:53 GMT Organization: <none> Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <30A1F1F9.167EB0E7@era-t.ericsson.se> References: <47itjt$65m@lhc.nlm.nih.gov> <sjcDHqMKM.MBG@netcom.com> NNTP-Posting-Host: physics2.berkeley.edu