Different Warnings Appear Using Different Optimizations (67078)



The information in this article applies to:

  • Microsoft C for MS-DOS 6.0
  • Microsoft C for MS-DOS 6.0a
  • Microsoft C for MS-DOS 6.0ax
  • Microsoft C for OS/2 6.0
  • Microsoft C for OS/2 6.0a
  • Microsoft C/C++ for MS-DOS 7.0
  • Microsoft Visual C++ 1.0
  • Microsoft Visual C++ 1.5
  • Microsoft Visual C++ 1.51
  • Microsoft Visual C++ 1.52
  • Microsoft Visual C++, 32-bit Professional Edition 2.0
  • Microsoft Visual C++, 32-bit Professional Edition 2.1
  • Microsoft Visual C++, 32-bit Professional Edition 2.2

This article was previously published under Q67078

SUMMARY

The information in this article is included in the documentation starting with Visual C++ 5.0. Look there for future revisions.

In Microsoft C/C++ compiler, different warning messages can appear during separate compilations of the same code when different optimizations are used. This is normal behavior that occurs because some warnings are found only while optimizing.

MORE INFORMATION

If the sample code below is compiled with /W4 (all warnings) and the /Os optimization (optimize for space), no warnings are found. However, when the code is compiled with /W4 and /Osle (optimize for size, loop, and global-register allocation), the following warning is generated:
file.c(7) : warning C4202: unreachable code
With Visual C++ for Windows NT versions 1.0, 2.0, and 2.1, as well as Visual C++ for Windows version 1.5 and 1.51, the following warning is generated when compiled with /W4 and /O2:
file.c(7) : warning C4702: unreachable code
There are several other optimizations and code examples that will exhibit this type of behavior. Once again, this is normal and serves to notify the developer that there MAY be a problem.

Sample Code

  #include <stdio.h>

  void main(void)
  {
       goto bottom;

       printf("Not used\n");    /* Code that is not used */ 

bottom:printf("Hello World!");
  }
				

Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kbcode kbCompiler KB67078