Results 1 to 4 of 4

Thread: Modify a float4 in a function

  1. #1

    Modify a float4 in a function

    Hi,

    I feel a bit stupid, I never had to deal with this simple problem in the past year.

    In my kernel I have two float4 variables : a and b.
    I want to call a function that will modify them.
    Is this working?

    Code :
    void f(float4 a, float4 b){
      a.x = 0;
      b.x = 1;
    }

    or should I use this?

    Code :
    void f(float4 * a, float4 * b){
      (*a).x = 0;
      (*b).x = 1;
    }

    If float4 is just a float[4], solution 1 should work no?
    Thanks for your help !

  2. #2
    Solution 1 will not work. The parameters a and b are local to the function and only contains copies of the variables passed when f is called.

  3. #3
    Quote Originally Posted by ibbles View Post
    Solution 1 will not work. The parameters a and b are local to the function and only contains copies of the variables passed when f is called.
    So how can I modify a float4 in a function f() is this float4 is a parameter of the function f() ?

  4. #4
    Your second suggestion will work; pass pointers to the function. Just remember that you may need to add address qualifiers to the function declaration.

Posting Permissions

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