KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q65302: Warning C4056: "Overflow in Constant Arithmetic" May Be Wrong

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

The compiler warning "C4056: Overflow in constant arithmetic" may be
erroneously generated by the compiler. The incorrect warning message
usually appears when accessing data in arrays. If the quick compile
(/qc) option is specified, the error message is not generated.

The C4056 warning is generated on warning level 2 (/W2) or higher.

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

// This code fragment will generate the C4056 error on the
// the two lines that reference rate_file.factor14[8][ctr]

#include <string.h>

struct PC_RATE_FILE
{
  char  kind[3];
  char  state[3];
  char  rate_date[7];
  long  base[20];
  long  factor01[40][20];
  long  factor02[40][20];
  long  factor03[40][20];
  long  factor04[40][20];
  long  factor07[40][20];
  long  factor08[40][20];
  long  factor09[40][20];
  long  factor10[40][20];
  long  factor11[40][20];
  long  factor12[40][20];
  char  factor14[40][20][8];
  long  factor15[40][20];
  char  valid_year[15][3];
  char  valid_terr[40][3];
  char  valid_class[40][3];
} rate_file;

int testit()
{
  long ctr;
  char test_string[80],*ptr;
  long test_rel;

  for (ctr=0;ctr<6;ctr++)
  {
    ptr = (char *)rate_file.factor14[8][ctr];
    strcpy (test_string,rate_file.factor14[8][ctr]);
    test_rel = rate_file.factor15[7][ctr];
  }

  return(1);
}

Microsoft has confirmed this to be a problem with C versions 6.00 and
6.00a. 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.