Home > Back-end >  Warning processing
Warning processing

Time:05-20

How to handle this warning, please advice

CodePudding user response:

Warning C26451

CodePudding user response:

Short int si;
int i;
I= (int) si + 10000.

CodePudding user response:

Warning content is to let you use 4 bytes into 8 bytes of data storage, because already overflow, post code, may be better to solve the problem ~

CodePudding user response:

refer to the second floor 4 teacher zhao response:
short int si;
int i;
I= (int) si + 10000.

Impending, zhao four old wet finally came back, you look at, don't let him run!
 short int si; 
int i;
I=(int) si + 10000;

Xi, zhao old wet: are you serious? Variable si not initialize or assign a value, moreover, 10000 is an integer constants, it is of type int, when doing the add operation, to do with the value of the variable si integer to ascend, ascension, the same as the type of the two operands are no longer a further conversion, direct to do addition,

Zhao old wet said, of course, I know, I just do an example to illustrate, don't care about these details, but I have a better example:
 char c; 
Int I=50;
C=I + 60 ull;

Zhao old wet, you see, this example is more obvious, alas, but the original poster of incomplete information, the somebody else to write the C programming language may not be

CodePudding user response:

The
references the building Lord Buddha salted fish en reply:
how to handle this warning, seek advice

For (int j=0; J & lt; 20; + + j)
{
[I] if (d==j)
{
[I] k=j;
break;
}
Else if (d [I] & gt; J & amp; & D [I] {
[I]=j k + 1;
break;
}

}

CodePudding user response:

reference 4 floor all ling rat man replies:
Quote: refer to the second floor 4 teacher zhao response:
short int si;
int i;
I= (int) si + 10000.

Impending, zhao four old wet finally came back, you look at, don't let him run!
 short int si; 
int i;
I=(int) si + 10000;

Xi, zhao old wet: are you serious? Variable si not initialize or assign a value, moreover, 10000 is an integer constants, it is of type int, when doing the add operation, to do with the value of the variable si integer to ascend, ascension, the same as the type of the two operands are no longer a further conversion, direct to do addition,

Zhao old wet said, of course, I know, I just do an example to illustrate, don't care about these details, but I have a better example:
 char c; 
Int I=50;
C=I + 60 ull;

Zhao old wet, you see, this example is more obvious, alas, but the original poster of incomplete information, the somebody else to write the C programming language may not be

Is a C language program

CodePudding user response:

reference 1st floor zgl7903 response:
Warning C26451

Have seen, a bit intimidating

CodePudding user response:

refer to fifth floor Buddha salted fish en reply:
Quote: refer to the building Lord Buddha salted fish en reply:
how to handle this warning, seek advice

For (int j=0; J & lt; 20; + + j)
{
[I] if (d==j)
{
[I] k=j;
break;
}
Else if (d [I] & gt; J & amp; & D [I] {
[I]=j k + 1;
break;
}

}


Nest ha, ha, ha, so, zhao four old wet will tell you, for the expression [I] d & lt; J + 1, on the basis of conventional arithmetic conversion (the Usual arithmetic conversions) rules, to calculate the sub-expression d [I] and the value of j + 1, then the two values are converted to the same type, then compare,

Sub-expression d [I] type is double, the result of the first press the table;

In the sub-expression j + 1, expression is of type int j, constant 1 type is int, is the result of the combined type int,

So, need to be the result of the subexpression j + 1 converting from its original type int type double,

But, at the time of calculation expression j + 1, if the value is a maximum of type int, j is the calculation could overflow, in this case, the compiler may be inclined to think that since expression j + 1 result sooner or later converted to a double, then, why don't you convert j or 1 in advance to double? So you can avoid overflow, for example:
[I] & lt;
 d (double) j + 1; 

Or
[I] & lt;
 d J + 1.0; 

Using either a way, for add operation, is to convert the conventional arithmetic, the first two operands are converted to double type, then the result of the combined natural will not overflow, the value of type double,
  • Related