Initialization of vectors (IBM extension)

A vector type is initialized by a vector literal or any expression having the same vector type. For example:
vector unsigned int v1;
vector unsigned int v2 = (vector unsigned int)(10);
v1 = v2;
C only

The AltiVec specification allows a vector type to be initialized by an initializer list. This feature is an extension for compatibility with GNU C.

Read syntax diagramSkip visual syntax diagram
Vector initializer list syntax

                                    .- ,----------.         
                                    V             |         
>>-vector_type----identifier--=--{----initializer-+--}--;------><

The number of values in a braced initializer list must be less than or equal to the number of elements of the vector type. Any uninitialized element will be initialized to zero.
The following code are examples of vector initialization using initializer lists:
vector unsigned int v1 = {1};  // initialize the first 4 bytes of v1 with 1
                               //	 and the remaining 12 bytes with zeros 

vector unsigned int v2 = {1,2};  // initialize the first 4 bytes of v2 with 1
                                 // and the next 4 bytes with 2

vector unsigned int v3 = {1,2,3,4};  // equivalent to the vector literal
                                     // (vector unsigned int) (1,2,3,4) 
Unlike vector literals, the values in the initializer list do not have to be constant expressions unless the initialized vector variable has static duration. Thus, the following code is legal:
int i=1;
int function() { return 2; }
int main()
{
   vector unsigned int v1 = {i, function()};
   return 0;
}
C only