KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q51620: No Warning When Passing Long to Int Prototyped Function

Article: Q51620
Product(s): See article
Version(s): 5.10   | 5.00
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | s_quickc s_quickasm | mspl13_c
Last Modified: 21-MAR-1990

If you prototype a function to accept an integer, and then pass a long
integer to the function, Microsoft C Version 5.01 and Microsoft QuickC
Versions 1.00, 1.01, 2.00, and 2.01 fail to give a warning about the
data conversion if the value being passed is between -65536 and
+65535. Instead, the value is converted to a valid integer (between
-32768 and 32767) and passed to the function, causing unexpected
results.

This is also a problem with the Microsoft QuickAssembler Version 2.01.

The following code demonstrates this problem:

#include <stdio.h>

void func(int,int);

void main(void)
{
     func(50000L,1L);    /* Can also pass in (long)50000,long(1)     */
}                        /* and have no warnings.                    */
                         /* Try changing to 100000, notice correct   */
                         /* warning.                                 */
void func(int a, int b)
{
     printf("a=%d  b=%d",a,b);
}

If you declare two long integers and pass them to func, as in the
following, you receive a data conversion warning as expected:

   long a=50000,b=1;
   func(a,b);

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.