[cfe-dev] Clang ext_vector_type sizeof()

Robinson, Paul Paul_Robinson at playstation.sony.com
Fri Aug 1 13:35:31 PDT 2014

> Is there any way of obtaining the declared size of a vector defined as:
> 	typedef float vec3 __attribute__((ext_vector_type(3)));
> Using sizeof(vec3) gives 16, I assume because 4 is faster than 3, but I
> can't find anything which will give "3" or "12" at compile-time or
> runtime. Certainly sizeof(((vec3)0).x) gives me sizeof(float), but that's
> as far as I got.

The Clang documentation is pretty sketchy, but googling
"opencl vector data types example" got me to this page:
which says:
For 3-component vector data types, the size of the data type is 
4 x sizeof(component). This means that a 3-component vector data type will be 
aligned to a 4 x sizeof(component) boundary.

So, the actual size of a vec3 is 16 presumably because OpenCL says so,
and you won't find any way to get "12" as an answer. Also seems unlikely
you'd find a way to get "3" out of it.

More information about the cfe-dev mailing list