All the examples that I could find on the Internet about increasing the pointer that causes segfault are related to dereferencing the pointer - what if I just want to increase it (for example, at the end of the for loop) and it doesn't matter if it gets into the wrong memory because I will not use it again. For example, in this program, I just need to perform step 4 at each iteration, but I never play these pointers again after the last iteration.
float* leftRowPointer, resultRowPointer; // assume they were correctly initialized for (unsigned int i = 0; i < 4; ++i, leftRowPointer += 4, resultRowPointer += 4) { // do some stuff }
Do I need to do something like this?
for (unsigned int i = 0; i < 4; ++i) { // same stuff if (i != 3) { leftRowPointer += 4; resultRowPointer += 4; } }
Is there a better way to accomplish what I'm trying to do?
When I tried it myself, nothing bad happens, but this hardly guarantees that it will always work, and, unfortunately, I do not have access to Valgrind or the like at work.
We use the C ++ 11 standard, fwiw, and I could not find anything there that directly relates to this, but I will be the first to admit that I do not know the standard well enough to have a good idea of where it is to search.
c ++ memory-management undefined-behavior pointers segmentation-fault
Dannnno
source share