Microsoft KB Archive/111357

From BetaArchive Wiki

BUG: C1017 Occurs with /Zg and #if

Q111357

1.00 1.50 WINDOWS kbtool kbbuglist ---------------------------------------------------------------------- The information in this article applies to: - The Microsoft C/C++ Compiler (CL.EXE), included with: - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 ---------------------------------------------------------------------- SYMPTOMS ======== A C1017 error is incorrectly generated when using /Zg and the preprocessor directive #if on an integer constant. For example, using #if 0 or #if 3 causes the following error: file.c(3) : fatal error C1017: invalid integer constant expression Note that the error also occurs when a symbol that evaluates to an integer constant is referenced in a #if directive. For example: #define ZERO 0 #if ZERO RESOLUTION ========== The following are two possible workarounds: - This error occurs only if the /Zg compiler switch is used. If it's not necessary, do not use /Zg with the file. -or- - If the expression being evaluated is 0 (zero), then it will never evaluate to true. If the expression is nonzero, then it will always evaluate to true. It should be possible to use #ifdef instead of #if (see MORE INFORMATION below). MORE INFORMATION ================ The most common reason for using an expression that always evaluates to an integer constant is to enable conditional compilation, which is dependent on a particular symbol being used. For example, the following code prints out information only when the MYDEBUG_BUILD_OPTION symbol is defined to be equal to 1: #include #define MYDEBUG_BUILD_OPTION 1 // Use #define MYDEBUG_BUILD_OPTION 0 to do a non-debug build. void main(void) { #if MYDEBUG_BUILD_OPTION printf("We are debugging\n"); #endif printf("Hello world\n"); } By following the second workaround (listed above), this code could be rewritten to use #ifdef: #include #define MYDEBUG_BUILD_OPTION // Remove the above line to do a non-debug build, or // eliminate the define and use the /D compiler option // to define MYDEBUG_BUILD_OPTION for debug builds. void main(void) { #ifdef MYDEBUG_BUILD_OPTION printf("We are debugging\n"); #endif printf("Hello world\n"); } STATUS ====== Microsoft has confirmed this to be a problem in the Microsoft C/C++ compiler versions 8.0 and 8.0c for MS-DOS. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available. Additional reference words: 1.00 1.50 8.00 8.00c KBCategory: kbtool kbbuglist KBSubcategory: CLIss

Keywords : kb16bitonly
Issue type : kbbug
Technology : kbVCsearch kbAudDeveloper kbCVCComp


Last Reviewed: May 5, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.