Okay, so I'm trying to do something that's probably pretty stupid. I'm writing a bit of code in C. I have an array of chars (1 byte). I need to work with 8 bytes at a time, so I've set a long long* pointer and dereference it every time I need to get data. I then need to move that pointer 4 bytes further into the array once I'm done with each iteration of a loop, so that the lower 4 bytes of the last iteration become the upper 4 bytes of the next.
I'm having trouble with that last step. Every time it's supposed to shift, I instead find that it's pointing to something else entirely. The upper 4 bytes are always the same, and the lower 4 bytes are always empty. Notably, the upper 4 bytes after a loop iteration should always be empty; it seems like I've offset my address by 4 bytes in the wrong direction. The entire loop smears those 4 bytes across the entire array, so I'm not just straight-up moving backwards, either.
Here's one form of the clearly incorrect syntax I'm using:
selection = (long long*)&shiftChecked[index];
where selection is a long long* pointer that points to the data I'm operating on, shiftChecked is an array of longs whose starting address is the same as the array of chars that I'm working on, and index is which of those I'm working on right now.
That fustercluck of spaghetti code was the result of trying to take the actual pointer arithmetic out of my hands entirely, but it seems to have exactly the same results as the earlier
selection = (long*) selection + 1;
How the devil does one even do this?
EDIT: Notably, switching to selection - 1 in the latter block causes the algorithm to work "correctly", but with quotes because it works on the data preceding the array in memory, and also in the reverse of what would be the correct order. If it comes to it, I can exploit this by reversing the binary string that makes up the array, starting at the end, and then unreversing it when I'm done. This is stupid though so if anybody has better ideas I still want to hear them, and even if I do this I'll probably still fuck it up somehow.