I'm building a 64bit C++ code on VS 2015.
DWORD testVar;
testVar= strLen((LPCSTR)src);
// where src is a CString.
Seeing Warning - C4267 'argument': conversion from 'size_t' to 'DWORD', possible loss of data.
Any suggestions will be helpful.
I'm building a 64bit C++ code on VS 2015.
DWORD testVar;
testVar= strLen((LPCSTR)src);
// where src is a CString.
Seeing Warning - C4267 'argument': conversion from 'size_t' to 'DWORD', possible loss of data.
Any suggestions will be helpful.
The error message says that it’s converting from
size_t
. This means that the original value has typesize_t
. Unless you have a reason you need to have aDWORD
instead, you should keep the same type, so you should instead doYou should keep the same data type because there is no chance of losing information that way, and it helps keep your application future-proof. If you used a 64-bit integer (which
size_t
probably is, because you’re on a 64-bit system), then you’d waste space if you ever wanted to compile for a 32-bit system, and you wouldn’t have enough space if you had more than 64 bits in asize_t
(which is probably pretty far off, but there are some specialized areas now where it would be useful even though it isn’t yet practical so who knows). In general, you should not convert to a different type until you need to, and for this you don’t need to yet.