[sv-bc] Clarifications needed in new for-loop var declaration syntax?

From: Rishiyur S. Nikhil <nikhil@bluespec.com>
Date: Mon Mar 08 2004 - 13:43:30 PST

Some of my colleagues felt that the description of the new for-loop
syntax in Sections 8.5 and 8.5.2 was unclear (which allows local
declaration of multiple loop variables).

Questions:

- Is it just the presence or absence of a data_type in front of the
   first loop-variable-assignment that determines

   - whether this is a new, local, variable,

   - or whether this must be an existing, pre-declared variable?

- The loop-initialization can have multiple variables, but is it the
   case that either all of them must be pre-declared or all must be
   locally declared, i.e., you cannot mix them? For example in,

         for (int i=0, j=0; ...)

   it appears from the syntax that j will also be a locally declared
   variable and will shadow any j in the surrounding scope, correct?

   Therefore, also, in the example at the bottom of Section 8.5.2,

         for (int count = 0, done = 0, int j = 0; ...)

   the second 'int' is ok but redundant, correct?

- It is unspecified whether these variables come into scope from left
   to right, e.g., in

         for (int i=5, j=3, k=i+j; ...)

   do the variables in 'i+j' refer to these newly declared variables or
   to variables in the surrounding scope?

It would be good to clarify these points in the LRM.

Nikhil
Received on Mon Mar 8 13:43:34 2004

This archive was generated by hypermail 2.1.8 : Mon Mar 08 2004 - 13:43:48 PST