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?


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

or should I use this?


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 !

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() ?

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