Ben*_*y K 0 c++ pointers memcpy
出于某种原因,我无法理解以下代码memcpy在循环中的第二个崩溃(没有任何错误消息;gcc 7.4.0 Ubuntu 16.04,QT5)所以我猜我的指针算法是错误的,但我不明白为什么:
#include <stdio.h>
#include <string.h>
#define ROWS 48
#define COLS 48
#define CHANNELS 3
#define NUM_PIX ((ROWS) * (COLS) * (CHANNELS))
struct MyImage
{
int width;
int height;
int channels;
unsigned char rawData[NUM_PIX];
};
int main()
{
const int numIm = 16;
MyImage theClsImArr[numIm];
unsigned char ImArr[numIm][ROWS][COLS][CHANNELS];
int Bytes2Copy = NUM_PIX * sizeof(unsigned char);
for (int i = 0; i < numIm; i++ )
memcpy(theClsImArr[i].rawData,ImArr + i * NUM_PIX ,Bytes2Copy ); // works when i = 0, crashes at i = 1
return 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |