casting vector types


If I have float a; short b; then a = (float)b; works.
If I have float3 a; short3 b; then for a = (float3)b; I get the following error:

error: C-style cast from vector 'short3' to vector 'float3' of different size

Is this a bug or correct and if it is correct how do I cast from short3 to float3?


I do not think this is a bug, this has been default behaviour in GCC and Clang for some time. IIRC, the rule is that vector casts are bitwise conversions, and sizeof(float3) != sizeof(short3).

You should be able to do something like this (assuming you use the ext_vector_extension):

typedef float __attribute__((ext_vector_type(3))) float3;
typedef short __attribute__((ext_vector_type(3))) short3;

float3 a;
short3 b;
a = (float3){(float)b.x, (float)b.y, (float)b.z};

/ Mattias