<
town...@astro.wisc.edu> wrote:
> On Wednesday, January 15, 2014 4:50:31 AM UTC-6, Anton Shterenlikht wrote:
> > The standard is very clear on this - 10-107r1, p. 178, lines 5-7:
> > *quote*
> >
> > A variable that is referenced in an iteration shall neither
> > be previously defined during that iteration,
> > or shall not be defined or become undefined during
> > any other iteration. A variable that is defined or
> > becomes undefined by more than one iteration becomes
> > undefined when the loop terminates.
> > *end quote*
[with my previously noted correction of "neither"->"either"]
> > Your code is standard compliant even without the BLOCK construct.
> It may be *compliant*, but the standard appears to be insufficient to
> determine what the output of this code will be. Will the code print out
> 100 numbers, starting at 0.5 and increasing by increments of 0.5? If it
> doesn't, is the compiler violating the standard?
I'm finding myself agreeing with Rich Townsend here. Looks to me like
the intent is to allow this sort of code, but I' don't see that the
cited words do it. Maybe other words do, but these words alone are not
enough. I haven't researched enough to be sure about the possible other
words.
If execution can indeed be concurrent, then it looks to me like the
words as posted don't provide an interpretation of what the result would
be. In that case, the code would be non-conforming because there's a bit
quite early in the standard that says code is non-conforming if the
standard doesn't provide an interpretation of it. We don't generally
like to rely on that rule, preferring to make it explicit that something
is nonconforming instead of having to deduce it that way; there have
been cases before where that kind of argument was used to justify that
something was nonconforming, but an erratum was published to make it
clearer by adding an explicit prohibition.
If the model in the standard is that the iterations are done in any
order, but not concurrently, then all would be well defined, although as
I mentioned before, there woukdn't be much reason for the construct if
that were the end of it.
Possibly (and please note that word, as I haven't researched enough to
be at all sure of it), the standard defines execution as though it were
in any order, but with the idea that the restrictions facilitate
allowing concurrent implementation. In that case, a concurrent
implementation would have to basically make B private to each iteration.
(Optimizing B out would have essentially the same effect).
Per Robert's note, just because the standard is intended to facilitate
concurrent implementation doesn't necessarily mean that all compilers
are required to or will manage to do so.