OpenCL C standard is based on the strict aliasing rules of the C99 standard. What is meant by strict aliasing rule? Consider the following example:
cl_int data; cl_int *pToIntData = &data; cl_short *pToShortData = (cl_short *)pToIntData; //Now one can access the sub data as follows cl_short hi = pToShortData[1]; cl_short lo = pToShortData[0];
In the preceding example pToShortData
is an alias to pToIntData
. According to C99 standard an alias cannot be created for the type other than the original. Though the preceding code will compile just fine and may result in a correct behavior since you are only reading from the aliased pointer, but when you write to an aliased pointer, compiler will result in a "strict aliasing rule broken" warning and will result in an undefined behavior. The GCC compiler will throw a warning at higher optimization levels. Similarly aliasing a vector type pointer to a different data type pointer is illegal, though it may be correct since built-in vector...