Error in pointer arithmetic

Hi there,

Can someone explain me why this code doesn’t work?

__kernel void foo(__global const uchar* a)
{
	__global const uchar* currentPosition = (__global uchar*) a;

	// Update the position
	currentPosition += 4;
}

When I try to read the value of bufferPosition after the increment I get the same result as when I don’t do the arithmetic.

Why is this happening?

Thank you.

It’s not very clear what your problem is. Can you post a minimal, complete example (something that can be compiled) that shows the issue?

Also, I believe that you have to enable the cl_khr_byte_addressable_store extension before you can reliably use char-sized pointers.

It is because


currentPosition += 4;

changes the value of the pointer currentPosition and not what the pointer points to. The operation becomes pointless since currentPosition is never used again in the kernel. Perhaps you really want


(*currentPosition) += 4;