c++ - 'uintmax_t'到 'size_t'和 'unsigned int'转换丢失的数据是多少?

标签 c++ boost int

我明白了:

warning C4244: 'initializing' : conversion from 'uintmax_t' to 'unsigned int', possible loss of data

在:

boost::shared_array<char> buffer( new char[file->size]);

……然后是这个:

warning C4244: 'argument' : conversion from 'uintmax_t' to 'size_t', possible loss of data

在:

boost::asio::write(*socket, boost::asio::buffer(buffer.get(), file->size));

我应该害怕还是没事?

最佳答案

可能 file->sizeuintmax_t 类型,它大于 operator new[]size_t > 取数组大小。通常第一个可以是 64 位整数,而第二个只能是 32 位。

实际上,当您尝试处理超过 4GB 的文件时,这会导致问题,因为 size_t 无法表示这么大的字节数。如果您只希望处理较小的文件,其中 size_t 足够大以存储文件大小,则不会有问题。

关于c++ - 'uintmax_t'到 'size_t'和 'unsigned int'转换丢失的数据是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7706171/

相关文章:

临时对象的 C++ 生命周期——这安全吗?

c# - 一起计算 sin 和 cos 的最快方法是什么?

C++, boost : which is fastest way to parse string like tcp://adr:port/into address string and one int for port?

mysql按整数和varchar排序

c++ - tbb::cache_aligned_allocator:使用 __m128i 获取 "request for member...which is of non-class type"。用户错误或错误?

c++ - 虚拟抽象方法的语义是什么?

c++ - 为什么我不能将 std::unordered_map 或 boost::unordered_map 与 boost::multiprecision 类型一起使用?

c++ - 循环文件写入的磁盘 IO 问题

python - 如何在python中将字符串列表转换为整数

MySQL:CONCAT/SUBSTRING:这不起作用,因为我使用的是 int 变量吗?