How to type-cast char* to int* in openCL

佐手、 提交于 2019-12-01 07:42:15

问题


Can any one tell me how to typecast a char* pointer to int* in OpenCL kernel function?? I tried ((int*) char_pointer) but it is not working.


回答1:


You have to qualify the pointer with the correct address space, I think.

If you don't specify the address space, __private is assumed, but your source pointer seems to be a __global pointer (from your comment), so the address spaces are incompatible.

So try to use (__global int*) instead of just (int*).




回答2:


Stuff the pointers in a union, initialize with a char*, use it with the int*:

 union {
     char *cp;
     int  *ip;
 } ptr;

 ptr.cp = allocatedBuf;
 a[0] = *(ptr.ip);

Ugly, but does the trick without casts, at least in C. It's undefined behaviour, but hey, you're not using this in a heart monitor or with nuclear warheads at the other end, right?



来源:https://stackoverflow.com/questions/10483445/how-to-type-cast-char-to-int-in-opencl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!