Results 1 to 4 of 4

Thread: Syntax of vector literals conflicts with C99 comma operator.

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    6

    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,

  2. #2
    Junior Member
    Join Date
    Apr 2009
    Posts
    5

    Re: Syntax of vector literals conflicts with C99 comma operator.

    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.

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    6

    Re: Syntax of vector literals conflicts with C99 comma operator.

    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:

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

  4. #4
    Junior Member
    Join Date
    Apr 2009
    Posts
    5

    Re: Syntax of vector literals conflicts with C99 comma operator.

    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.

Similar Threads

  1. Replies: 3
    Last Post: 05-14-2011, 04:53 PM
  2. Support for fenv.h as in C99
    By votsor in forum Suggestions for next release
    Replies: 0
    Last Post: 01-25-2011, 02:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •