KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q64565: #if Uses Only Lower 2 Bytes of Expression for Test

Article: Q64565
Product(s): See article
Version(s): 6.00   | 6.00
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | buglist6.00 | mspl13_c
Last Modified: 31-AUG-1990

The #if compiler directive uses only the lower 2 bytes of the
evaluated expression when testing for true or false.

The following code, when compiled using the C 6.00 compiler, will
evaluate the #if expression to false, when it should evaluate to
true since the number is non-zero:

Sample Code
-----------

void main (void)
{
#if 0xFFFF0000L
  printf("TRUE\n");
#else
  printf("FALSE\n");
#endif
}

According to the ANSI standard (Section 3.8.1), any long expression in
an #if directive must be evaluated as if it were a long value.

The workaround for this problem is to only use 2-byte expressions in
an #if directive.

Microsoft has confirmed this to be a problem with the Microsoft C
Compiler version 6.00. We are researching this problem and will post
new information here as it becomes available.

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.

Copyright Microsoft Corporation 1986-2002.