Syntax of vector literals conflicts with C99 comma operator.

Hi,

“6.1.6 Vector Literals” of opencl-1.0.33.pdf defines syntax of Vector literals.
But, this syntax conflicts with C99 comma operator.

For example:
“float4 f = (float4)(1.0f, 2.0f, 3.0f, 4.0f);”

This statement is interpreted as:
“float4 f = (1.0f,2.0f,3.0f, (float4)4.0f);”
in C99.

and, according to last example:
“float4 f = (float4)(1.0f, 2.0f); <- error”
this statement should be treated as error.

But, this statement is valid on C99.
This statement is interpreted as:
“float4 f = (1.0f, (float4)2.0f); <- OK”

How should I distinguish “vector literal” from operand of comma operator?

Thanks,

Yes, I think this was a bad idea. It is the same in AltiVec. Vector literals must always be preceded by a cast, so the sequence (VECTORTYPE)( starts a vector literal inside which commas have a different meaning.

Thanks for your reply.

And, can I use an other symbol that is defined to vector type as cast typename of vector literal.
Like as follows:


typedef uint4 ui4_t;
ui4_t x = (ui4_t)(1,2,3,4);

I have no idea, but I think so.

I’ll note that GCC allows using a (float4){1.0,2.0,3.0,4.0} for its vector extensions.