This documentation is archived and is not being maintained.

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


Use /Zc:forScope if you want standard C++ behavior for for loops with Microsoft extensions (/Ze).

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

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

int main() {
// 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 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.

For more information about conformance issues with Visual C++, see Standard 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 Setting Visual C++ Project Properties.
  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 ForceConformanceInForLoopScope Property.

See Also

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