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

前端 未结 2 2047
礼貌的吻别
礼貌的吻别 2021-01-14 15:28

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 wo

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-14 16:11

    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?

提交回复
热议问题