(*pointer) ++ in cuda c

In my code I have an int *blah passed into a device function.

In that function I have: *blah++

That code does not function. It does not increment the memory location.

I had to change it to *blah = *blah + 1; Then it worked.

Is that a bug or does cuda c not support ++?

If cuda c does not support ++ why do I not get an error when it compiles?

I’m using SDK 8.0.61.

To first order, CUDA is a subset of C++. The semantics of the ‘*’ and ‘++’ operators in CUDA therefore match those in C++.

The sparse information provided about your code indicates that you have a bug (or possibly multiple bugs) in your code. A compiler cannot catch all programming errors, only some. In particular it cannot usually catch semantic errors.

I would suggest acquiring an introductory text on C++ for self study, and to use it along with the CUDA documentation. You might want to check in particular those portions of the book that deal with pointers, operators, and operator precedence.

It’s pretty simple really.

I could create a test case, but I don’t have time.

I changed this code:

*pcnt++;

to this:

*pcnt+=1;

and it started working.

With the original code, print statements showed that *pcnt was not incrementing.

With the changed code (both *pcnt+=1 and *pcnt=*pcnt+1) worked and the code behaved as expected.

i had the same error just a few weeks ago in CPU code :)

so no, it’s not a cuda, it’s c++. (*ptr)++ increments ptr

Thanks.