conversion from 'double' to 'DWORD', possible loss of data
Question
I have added a resource in my project. Its size is 4.096 byte. i need to assign it to DWORD because 3rd argument of WriteFile() needs it.
WriteFile(hFile, pExeResource,size, &bytesWritten, NULL);
So i cast it like this:
UPDATE2: DWORD bootsize = 4096; //and still warns me But i get this warning. can you plesae help me?
Solution
I think this is a combination of regional/language differences along with C-syntax.
I assume you mean 4.096
to be 4,096
with a comma separator. (Due to regional/language differences, you probably use .
instead of ,
.)
In C/C++, you don't use the separators. Just do this instead:
DWORD bootsize = (DWORD)4096;
OTHER TIPS
4.096
is a floating point value (of type double
), just less than 4.1, while DWORD
is an integral type (usually something like an unsigned int
). Naturally you lose the fractional part of the floating-point value in the conversion. (Perhaps you meant the integer value 4096
(no punctuation)?)
4.096
is four and 96/1000ths of a byte. I think you just want 4096
. Then you don't have to cast. Typically you don't use a comma or period in numbers in programming unless you really mean it as a decimal point.