1

I'm new to OpenCL and I'm trying to implement a simple function in OpenCL. The function is supposed to be called from a kernel function.

void swap(int *a, int *b)
{
    int *temp = a;
    b = a;
    a = temp;
}

However upon calling it, the swap doesn't work.

Is there a way to pass parameters by reference?

1
  • 3
    You're not swapping anything in your function though... Commented Aug 21, 2012 at 16:34

1 Answer 1

4

The way you have written the function, it is not doing anything. You are just assigning the pointers around. You need to have this:

void swap(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

Reference parameters are not allowed, as far as I recall.

Sign up to request clarification or add additional context in comments.

1 Comment

surely you mean *a=*b; *b=temp;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.