Condividi tramite


/Zc:forScope (Force Conformance in for Loop Scope) 

Used to implement standard C++ behavior for The for Statement loops with Microsoft extensions (/Za, /Ze (Disable Language Extensions)). /Zc:forScope is on by default.

/Zc:forScope[-]

Remarks

Standard behavior is to let a for loop's initializer go out of scope after the for loop. Under /Za, /Ze (Disable Language Extensions), the for loop's initializer remains in scope until the local scope ends.

The following code will compile under /Ze but not under /Za:

// zc_forScope.cpp
// compile with: /Zc:forScope- /Za
// C2065 expected
int main() {
   // Uncomment the following line to resolve.
   // int i;
   for (int i =0; i < 1; i++)
      ;
   i = 20;   // i has already gone out of scope under /Za
}

If you use /Zc:forScope-, you will get a warning (off by default) if a variable is in scope because of a declaration that was made in a previous scope. To demonstrate this, remove the // characters in the above code to declare int i.

You can modify the run-time behavior of /Zc:forScope with the conform pragma.

If you use /Zc:forScope- in a project with an existing .pch file, /Zc:forScope- is ignored (with a warning) and compilation continues with the existing .pch files. If you want a new .pch file generated, use /Yc (Create Precompiled Header File).

For more information about conformance issues with Visual C++, see Compatibility and Compliance Issues in Visual C++.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Modifying Project Settings.

  2. Click the C/C++ folder.

  3. Click the Language property page.

  4. Modify the Force Conformance in For Loop Scope property.

To set this compiler option programmatically

See Also

Reference

/Zc (Conformance)
/Za, /Ze (Disable Language Extensions)