Accessing the vector elements

Chris Lattner clattner@apple.com
Tue Oct 24 03:27:00 GMT 2006


On Oct 23, 2006, at 7:05 PM, Ian Lance Taylor wrote:

> Aren Villanueva <aren@indigo-designs.info> writes:
>
>> How would I access the vector elements in that vector float??
>> I can't seem to find any comprehensive information on this topic.
>
> gcc doesn't implement [] for vectors.  The only way to access the
> elements is something like:
>
>     union
>     {
>       vectortype v;
>       float af[4];
>     } u;
>     u.v = v;
>     return u.af[0];
>
> Ian

Or, alternatively:

vectortype v;

elementtype e = ((elementtype*)&v)[1]

-Chris



More information about the Gcc-help mailing list