次の方法で共有


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

 

The latest version of this topic can be found at -Zc:forScope (Force Conformance in for Loop Scope).

Used to implement standard C++ behavior for for loops with Microsoft extensions (/Ze). /Zc:forScope is on by default.

Syntax

/Zc:forScope[-]  

Remarks

The /Zc:forScope- option is deprecated and will be removed in a future release. Use of /Zc:forScope- generates deprecation warning D9035.

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

The following code compiles under /Ze but not under /Za:

// zc_forScope.cpp  
// compile by using: cl /Zc:forScope- /Za zc_forScope.cpp  
// C2065, D9035 expected  
int main() {  
    // Compile by using cl /Zc:forScope- zc_forScope.cpp  
    // to compile this non-standard code as-is.  
    // Uncomment the following line to resolve C2065 for /Za.  
    // 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-, warning C4288 (off by default) is generated 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 example code to declare int i.

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

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

For more information about conformance issues in Visual C++, see Nonstandard Behavior.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Working with Project Properties.

  2. In the navigation pane, open the Configuration Properties, C/C++, Language property page.

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

To set this compiler option programmatically

See Also

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