'uintmax_t'到'size_t'和'unsigned int'转换的数据丢失是多少? [英] What is the loss of data in 'uintmax_t' to 'size_t' and 'unsigned int' conversion?
问题描述
我明白了:
警告C4244:'初始化':从'uintmax_t'转换为'unsigned int',可能会丢失数据
warning C4244: 'initializing' : conversion from 'uintmax_t' to 'unsigned int', possible loss of data
on:
boost::shared_array<char> buffer( new char[file->size]);
...然后这个:
警告C4244:'参数':从'uintmax_t'转换为'size_t',可能丢失数据
warning C4244: 'argument' : conversion from 'uintmax_t' to 'size_t', possible loss of data
on:
boost::asio::write(*socket, boost::asio::buffer(buffer.get(), file->size));
我会害怕还是没事?
推荐答案
可能 file-> size
的类型为 uintmax_t
大于 size_t
,运算符new []
占用数组大小。通常,第一个可能是64位整数,而第二个只能是32位。
Probably file->size
is of type uintmax_t
which is larger than the size_t
that operator new[]
takes for the array size. Typically the first one could be a 64bit integer while the second one would only be a 32bit.
实际上,当您尝试处理超过4GB的文件时,这会导致问题,因为 size_t
不能代表如此大量的字节。如果您只希望处理较小的文件,其中 size_t
足以存储文件大小,则不会出现问题。
Practically this will lead to problems when you are trying to handle files over 4GB, because the size_t
can't represent such a large number of bytes. If you only expect to handle smaller files where size_t
is large enough to store the file size, there won't be a problem.
这篇关于'uintmax_t'到'size_t'和'unsigned int'转换的数据丢失是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!