
> 其他开发 > 'uintmax_t'到'size_t'和'unsigned int'转换的数据丢失是多少?(What is the loss of data in 'uintmax_t' to 'size_t' and 'unsigned int' conversion?)
其他开发IT屋2018/8/6 19:56:25
百度翻译此文有道翻译此文
问 题
I get this:
warning 244: 'initializing' : conversion from 'uintmax_t' to 'unsigned int', possible loss of data
on:
boost::shared_array<char> buffer( new char[file->size]);
…and then this:
warning 244: 'argument' : conversion from 'uintmax_t' to 'size_t', possible loss of data
on:
boost::asio::write(*socket, boost::asio::buffer(buffer.get(), file->size));
Shall I be scared or it is ok?

解决方案
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.
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.
本文地址:IT屋 What is the loss of data in 'uintmax_t' to 'size_t' and 'unsigned int' conversion?
问 题
我知道了:
警告244:'初始化':从'uintmax_t'转换为'unsigned int',可能会丢失数据
on:
升压:: shared_array<炭> buffer(new char [file-> size]);
...然后这个:
警告244:'参数':从'uintmax_t'转换为'size_t',可能丢失数据
on:
boost :: asio :: write(* socket,boost :: asio :: buffer(buffer.get() ,file-> size));

我会担心还是没事?
解决方案
可能 file-> size 的类型为 uintmax_t 大于 size_t ,运算符new [] 占用数组大小。通常,第一个可能是64位整数,而第二个只能是32位。
实际上,当您尝试处理达到4GB的文件时,这会导致问题size-t和unsigned int,因为 size_t 不能代表这么长期的字节。如果您只期望处理较小的文件,其中 size_t 足以存储文件大小,则不会出现问题。
本文地址:IT屋 'uintmax_t'到'size_t'和'unsigned int'转换的数据丢失是多少?

扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起
官方交流群:
Google Facebook Youtube 科学上网》戳这里《
百度翻译此文有道翻译此文
问 题

我知道了:
警告244:'初始化':从'uintmax_t'转换为'unsigned int'size-t和unsigned int,可能会丢失数据
on:
升压:: shared_array<炭> buffer(new char [file-> size]);
...然后这个:
警告244:'参数':从'uintmax_t'转换为'size_t',可能丢失数据
on:
boost :: asio :: write(* socket,boost :: asio :: buffer(buffer.get() ,file-> size));
我会担心还是没事?
解决方案
可能 file-> size 的类型为 uintmax_t 大于 size_t ,运算符new [] 占用数组大小。通常,第一个可能是64位整数,而第二个只能是32位。
实际上,当您尝试处理达到4GB的文件时,这会导致问题,因为 size_t 不能代表这么长期的字节。如果您只期望处理较小的文件,其中 size_t 足以存储文件大小,则不会出现问题。
本文地址:IT屋 'uintmax_t'到'size_t'和'unsigned int'转换的数据丢失是多少?

问 题
I get this:
warning 244: 'initializing' : conversion from 'uintmax_t' to 'unsigned int', possible loss of data
on:
boost::shared_array<char> buffer( new char[file->size]);
…and then this:
warning 244: 'argument' : conversion from 'uintmax_t' to 'size_t', possible loss of data
on:
boost::asio::write(*socket, boost::asio::buffer(buffer.get(), file->size));
Shall I be scared or it is ok?
解决方案
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.
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.
本文地址:IT屋 What is the loss of data in 'uintmax_t' to 'size_t' and 'unsigned int' conversion?

扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注与百万开发者在一起
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-128907-1.html
不用大陆动手
没用
100架P3C啊