How to convert array of cl_uint into array of cl_uchar in C++?

Hi,

I’d like to cast array of cl_uint into array of cl_uchar in C++.

How can I do that?

Regards,
Pit

[QUOTE=python;29410]Hi,

I’d like to cast array of cl_uint into array of cl_uchar in C++.

How can I do that?

Regards,
Pit[/QUOTE]

When you say cast the array what exactly do you mean? Someone correct me if I’m wrong but I believe that cl_uint and cl_uchar are basically the same as unsinged int and unsigned char on most systems so you would cast them the same you would any old data type.
Need a single value?

 cl_uchar Value = (cl_uchar)array_of_cl_uint[0]; 

Want to cast the whole array? well… you cant really. if you try to just cast it, the data wont line up properly, what you would have to do is copy it something like this,


cl_uint OldData[100];
cl_uchar NewData[100];

//Fill OldData

for (int i = 0; i < 100; i++)
{
    NewData[i] = (cl_uchar)(OldData[i]);
}

Of course this all assumes that the data in the cl_uints is valid to be shortened to a char with max value of 255.

In Clew on Windows, cl_uint is 32 bit, cl_uchar is 8 bit. Do you want to reinterpret your uint as 4 uchar? or just one uint to 1 uchar?
if you want to interpret one uint as 4 uchar the easiest way would be a c style cast i think. If the compiler argus about this, a memcpy could help maybe.
If you want to interpret one uint as one uchar, the iteration might be the only way to solve that i think.