考虑以下代码:
typedef float image_buffer[1024][1024];
void f(image_buffer *b)
{
for (int i = 0; i < 1024; i++)
{
for (int j = 0; j < 1024; j++)
{
b[i][j] = 0; // doesn't work
(*b)[i][j] = 0; // also doesn't work
}
}
}
人们抱怨没有问题,但是问题很明显,如何索引具有指向它的指针的固定大小数组?
谢谢!
编辑:OpenCL代码:
typedef float image_buffer[1024][1024];
__kernel void kernel1(sampler_t smp, read_only image2d_t a, read_only image2d_t b, __global image_buffer *r)
{
__local float shared[16][16];
float4 colorA = read_imagef(a, smp, (int2)(get_global_id(0), get_global_id(1))),
colorB = read_imagef(b, smp, (int2)(get_global_id(0), get_global_id(1)));
(*r)[get_global_id(0)][get_global_id(1)] = (colorA.x - colorB.x) * (colorA.x - colorB.x) + (colorA.y - colorB.y) * (colorA.y - colorB.y) + (colorA.z - colorB.z) * (colorA.z - colorB.z) + (colorA.w - colorB.w) * (colorA.w - colorB.w);
}
最佳答案
也许您打算写:
typedef float** image_buffer;
无论如何,正确的语法是:
(*b)[i][j] = 0;