How to fix compiler warning ?
-
I have the following code:
void* fixaddr; DWORD delta . . . *((WORD *)fixaddr) += HIWORD(delta); . . .
During compilation I get the following error: warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data Since I don't want any warnings appear in my code I wonder how to fix this ? -
I have the following code:
void* fixaddr; DWORD delta . . . *((WORD *)fixaddr) += HIWORD(delta); . . .
During compilation I get the following error: warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data Since I don't want any warnings appear in my code I wonder how to fix this ?You could turn down the warning level :)
-
I have the following code:
void* fixaddr; DWORD delta . . . *((WORD *)fixaddr) += HIWORD(delta); . . .
During compilation I get the following error: warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data Since I don't want any warnings appear in my code I wonder how to fix this ?cast HIWORD result to WORD: *((WORD *)fixaddr) += (WORD)HIWORD(delta);
-
I have the following code:
void* fixaddr; DWORD delta . . . *((WORD *)fixaddr) += HIWORD(delta); . . .
During compilation I get the following error: warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data Since I don't want any warnings appear in my code I wonder how to fix this ?I have reduced warning level to 3, and this warning does not appear. Thanks for help!
-
I have reduced warning level to 3, and this warning does not appear. Thanks for help!
Which does nothing but mask this and other potential problems. Leave the compiler warning level at 4 and fix the problem correctly. The compiler generates warnings/errors for a reason. If something wasn't suspect, there'd be no reason to warn you.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
cast HIWORD result to WORD: *((WORD *)fixaddr) += (WORD)HIWORD(delta);
Which makes little sense since the
HIWORD()
macro already casts its result to aWORD
. Theint
that the compiler is complaining about is on the left of the+=
operator, not the right.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
Which does nothing but mask this and other potential problems. Leave the compiler warning level at 4 and fix the problem correctly. The compiler generates warnings/errors for a reason. If something wasn't suspect, there'd be no reason to warn you.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
Which makes little sense since the
HIWORD()
macro already casts its result to aWORD
. Theint
that the compiler is complaining about is on the left of the+=
operator, not the right.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
I don't understand why, since the expression on the left IS a WORD. And we have no knowledge of this HIWORD macro; it maybe does not cast to a WORD.