简体   繁体   English

从size_t转换为DWORD,可能会丢失数据

[英]Conversion from size_t to DWORD, possible loss of data

I'm building a 64bit C++ code on VS 2015. 我正在VS 2015上构建64位C ++代码。

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. 看到警告-C4267'argument':从'size_t'到'DWORD'的转换,可能丢失数据。

Any suggestions will be helpful. 任何建议都会有所帮助。

The error message says that it's converting from size_t . 错误消息表明它正在 size_t转换。 This means that the original value has type size_t . 这意味着原始值的类型为size_t Unless you have a reason you need to have a DWORD instead, you should keep the same type, so you should instead do 除非您有理由需要DWORD ,否则应保持相同的类型,因此应改为

size_t testVar = strLen((LPCSTR)src);

You 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 a size_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). 如果您使用64位整数(因为在64位系统上,则可能是size_t ),那么如果您想为32位系统进行编译,则会浪费空间,而您不会如果size_t中有64位以上,则有足够的空间(这可能相差很远,但是现在有一些专门的区域,即使它尚不实用,它还是很有用的,谁知道)。 In general, you should not convert to a different type until you need to, and for this you don't need to yet. 通常,除非需要,否则不应转换为其他类型,为此,您不需要这样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告-从size_t转换为DWORD,可能会丢失数据 - Warning - Conversion from size_t to DWORD, possible loss of data 警告C4267“正在初始化”:从“ size_t”到“ DWORD”的转换,可能丢失数据 - Warning C4267 'initializing': conversion from 'size_t' to 'DWORD', possible loss of data 警告C4244:'参数':从'SIZE_T'转换为'DWORD',可能会丢失数据 - warning C4244: 'argument' : conversion from 'SIZE_T' to 'DWORD', possible loss of data 从“size_t”到“const double”的转换,可能会丢失数据 - conversion from 'size_t' to 'const double', possible loss of data C4267:“返回”:从“ size_t”转换为“ const UINT”,可能丢失数据 - C4267: 'return' : conversion from 'size_t' to 'const UINT', possible loss of data C4244:“+=”:从“std::streamsize”到“size_t”的转换,可能丢失数据 - C4244: '+=' : conversion from 'std::streamsize' to 'size_t', possible loss of data Visual Studio 中的警告 C4267:“参数”:从“size_t”转换为“const _Elem”,可能丢失数据 - Warning C4267 in Visual Studio: 'argument': conversion from 'size_t' to 'const _Elem', possible loss of data 'uintmax_t'到'size_t'和'unsigned int'转换的数据丢失是多少? - What is the loss of data in 'uintmax_t' to 'size_t' and 'unsigned int' conversion? 从'size_t'转换为'rapidjson :: SizeType' - conversion from 'size_t' to 'rapidjson::SizeType' 从 size_t 转换为 int 可能会丢失数据 - Possible Lost of Data Converting from size_t to int
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM