James Newton, Host wrote: >>> for (expression1; expression2; expression3) >>> >>> >>> is handled by the compiler as >>> >>> expression1; >>> while (expression2) >>> { >>> ; >>> expression3; >>> } >>> >>> and can be either a simple or a compound statement. >> >> Microsoft's latest C++ is interpreting it as: >> >> { >> expression1; >> while (expression2) >> { >> ; >> expression3; >> } >> } > > Huh? I don't see any difference. Does the extra set of braces matter? Yes. You can declare variables in expression1, and the presence or not of the (invisible) extra set of braces determines the scope of the variables that are defined in expression1. Without the extra set, they are valid until the end of the enclosing block (whatever that is); with it, they are valid only within the for loop. The problem is that the definition with the extra set of braces has been standard for ten years or more, but some compilers didn't handle it this way and may now be moving towards the standard. See for example http://www.csci.csusb.edu/dick/c++std/cd2/stmt.html (dated 11/1996) and browse to section 6.5.3: ----- quote ----- 6.5.3 The for statement [stmt.for] 1 The for statement for ( for-init-statement conditionopt ; expressionopt ) statement is equivalent to { for-init-statement while ( condition ) { statement expression ; } } except that names declared in the for-init-statement are in the same declarative-region as those declared in the condition, and except that a continue in statement (not enclosed in another iteration statement) will execute expression before re-evaluating condition. [Note: Thus the first statement specifies initialization for the loop; the condi- tion (_stmt.select_) specifies a test, made before each iteration, such that the loop is exited when the condition becomes false; the expression often specifies incrementing that is done after each itera- tion. ] 2 Either or both of the condition and the expression can be omitted. A missing condition makes the implied while clause equivalent to while(true). 3 If the for-init-statement is a declaration, the scope of the name(s) declared extends to the end of the for-statement. [Example: int i = 42; int a[10]; for (int i = 0; i < 10; i++) a[i] = i; int j = i; // j = 42 --end example] ----- end quote ----- Some VC++ background on this issue: http://vcfaq.mvps.org/lang/1.htm There is probably a compiler switch that allows selecting one or the other interpretation. Gerhard -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist