Results 1 to 3 of 3

Thread: Error in pointer arithmetic

  1. #1
    Junior Member
    Join Date
    Oct 2011

    Error in pointer arithmetic

    Hi there,

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

    Code :
    __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.

  2. #2

    Re: Error in pointer arithmetic

    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.

  3. #3

    Re: Error in pointer arithmetic

    It is because
    Code :
    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
    Code :
    (*currentPosition) += 4;

Similar Threads

  1. Replies: 1
    Last Post: 12-27-2012, 05:03 PM
  2. Arbitrary-precision arithmetic
    By BratSinot in forum OpenCL
    Replies: 3
    Last Post: 12-15-2011, 10:44 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
Proudly hosted by Digital Ocean