c++ - 如何将 unsigned Short 数组转换为 int 数组?

标签 c++ c arrays casting

我有 2 个数组:

unsigned short* array1;
int* array2;

有没有一种快速方法可以将 array1 中的所有数据放入 array2 中,使得 array2[0]=array1[0], array2[1] = array1[1] 的值 ..等等

我的问题提到了选角,但我认为这是一厢情愿的想法! 显然,我可以使用 for 循环逐个元素地执行此操作,但我正在编写一个图像处理应用程序,速度是关键。如果不类型转换的话还有其他解决办法吗?谢谢。

最佳答案

How do I cast array of unsigned short to an array of int?

你不知道。如果您这样做,并且使用结果,您将获得一些很好的未定义行为。

Is there a quick way to get all the data in array1 into array2

是的,复制数组元素。在任何像样的现代计算机上它都会很快。

关于c++ - 如何将 unsigned Short 数组转换为 int 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23131289/

相关文章:

ASP.NET MVC-如何将数组传递给 View ?

c++ - 如何在 OpenAL 中获取具有单个缓冲区的源的长度(持续时间)?

c - 如何在 Arduino 串口打印对 AT 命令的响应?

C中带空格的char转换为int

javascript - 为什么 for..in() 循环不返回数组内部的对象?

arrays - Prometheus 配置文件与 Puppet : how to handle quotes and brackets in yaml config file?

c++ - 使用 _wtol 与小数转换

c++ - C++20 模块中的静态库链接错误

c++ - Parenting Box2D body

c - 大小 8 的无效读取 .. by