PDA

View Full Version : Syntax of vector literals conflicts with C99 comma operator.



tanakamura
04-06-2009, 10:21 PM
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,

bonz
04-23-2009, 06:29 AM
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.

tanakamura
04-23-2009, 10:51 PM
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);

bonz
04-23-2009, 11:22 PM
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.