PRB: C4056: "Overflow in Constant Arithmetic" May Be Wrong

ID Number: Q65302

6.00 6.00a 6.00ax 7.00 | 6.00 6.00a

MS-DOS | OS/2

Summary:

SYMPTOMS

The Microsoft C compiler versions 6.0, 6.0a, 6.0ax, and C/C++

version 7.0 may generate the following warning:

warning C4056: Overflow in constant arithmetic

The warning message usually appears when accessing data in arrays.

The sample program below can be used to illustrate this problem. If

the quick compile (/qc) option is specified, the error message is

not generated. The C4056 warning is generated at warning level 2

(/W2) or higher.

STATUS

This behavior is by design.

More Information:

Sample Code

-----------

/* Compile options needed : none

*/

/* 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);

}

Additional reference words: 6.00 6.00a 6.00ax 7.00