Chris, As I recall, this was actually ambiguous in a previous LRM revision. It was not clear whether some variables were being declared (and inheriting a data type from earlier in the declaration), or just being initialized. However, the text you quoted now clarifies this: > for ( int count = 0, done = 0, j = 0; j * count < 125; j++, count++) > $display("Value j = %d\n", j ); > "In a for loop initialization, either all or none of the control variables > are locally declared. In the second loop of the last example, count, done > and j are all locally declared." > >How do we differentiate between variables that get declared and those that just >get initialized? In this example, why are "done" and "j" locally declared? Because count was locally declared (note the datatype "int"), and either all or none are locally declared. As soon as count was locally declared, they all were. > What if I already had a "done" declared in this scope - would a new variable be declared? Yes, because all or none are locally declared. There may still be a problem here. What happens with for (count = 0, int done = 0; !done; count++) The rule about "all or none" means that the declaration of done requires that count be declared. But there was no type on count. The parser has presumably already treated it as an initialization, not a declaration. You can't treat it as a declaration if you wanted to, since it doesn't have a type. So, is this considered a syntax error? Or should the "all or none" rule have been replaced with something like "after a local declaration, all subsequent variable initializations are also local declarations"? Steven Sharp sharp@cadence.comReceived on Fri Oct 28 13:27:29 2005
This archive was generated by hypermail 2.1.8 : Fri Oct 28 2005 - 13:27:49 PDT