BUG: C1017 Occurs with /Zg and #if

Last reviewed: July 22, 1997
Article ID: 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 <stdio.h>

   #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 <stdio.h>

   #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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.