Microsoft KB Archive/67040

{|
 * width="100%"|

BUG: /Ol Causes Register Variables to Be Allocated on Stack

 * }

Q67040

6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00 1.50 MS-DOS | OS/2 | WINDOWS kbtool kbbuglist -- The information in this article applies to: - The C/C++ Compiler (CL.EXE) included with: - Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax - Microsoft C for OS/2, versionS 6.0 and 6.0a - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 -- SYMPTOMS ======== In most cases, a variable declared with the register storage-class in Microsoft C versions 6.0, 6.0a, 6.0ax, and C/C++ version 7.0 will not be allocated to a register if loop optimization (/Ol) is enabled. Instead, the compiler will place the variable on the stack. The register storage will be allocated only if the function contains an inline assembly (_asm) block, because the inline assembly takes precedence over optimization. This is reflected by the following warning message, which is generated when /Ol is used on a function with an _asm block: warning C4204: in-line assembler precludes global optimizations STATUS ====== Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here as it becomes available. This is not a problem in the 32-bit compilers. MORE INFORMATION ================ The sample program below demonstrates both of the situations described above. If the program is compiled as is with /Ol, the register declared variable &quot;i&quot; will not be put in a register; it will be handled exactly like &quot;j&quot;, which is not declared with register storage-class. If the line at the end of main with the _asm block is uncommented, then &quot;i&quot; will be allocated storage in a register and the C4204 warning will be displayed if the warning level is set at 3 or 4 (/W3 or /W4). To see the difference, you can generate an assembly listing with /Fa, or you can compile and link the program with CodeView information and then view the mixed source and assembly listing in the debugger. Sample Code --- /* Compile options needed: /Ol /Fc /W3 */ int func(void); void main(void) { register int i = 7; int j = 9; while ( i < 10 ) { i += func; j += func; } /* Uncomment the following line to have i put in a register */ /* _asm xor i,i */ } int func(void) { return (1); } Additional reference words: 1.00 1.50 6.00 6.00a 6.00ax 7.00 8.00 8.00c KBCategory: kbtool kbbuglist KBSubcategory: CLIss

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCVCComp