【发布时间】:2016-11-09 18:01:58
【问题描述】:
我遇到了一个有趣的问题:如果我在函数内部定义一个数组,它可以正常工作,但是如果我在函数外部定义相同的数组并将其作为参数传递,则该数组的行为会有所不同。
void main()
{
unsigned short arr[8] = {0,1,2,3,4,5,6,7};
fun([...], arr);
}
void fun([...], unsigned short * arr, [...])
{
[...]
unsigned short fun_arr[8] = {0,1,2,3,4,5,6,7};
for(int i = 0; i < 8; i++)
if(arr[i] != fun_arr[i])
printf("Not the same");
//until here it works. the arrays are the same, I get no output, as expected
//this works just fine aswell
float f = some_float_array[fun_arr[0]];
//this works aswell
unsigned short index_from_arr = arr[0];
//this doesnt. The program crashes (-9999, which isnt an actual OpenCL error)
float f = some_float_array[arr[0]];
}
【问题讨论】: