| I dont know either. int somearray[10]; new_ptr = somearray + signed_value; or element = somearray[signedvalue]; this seems almost criminal to how my brain does logic/C code. The only thing i could think of is this: somearray+=11;
somearray[-1] // index set to somearray[10] ?? if i'd see my CPU execute that i'd want it to please stop. I'd want my compiler to shout at me like a little child, and be mean until i do better. -Wall -Wextra -Wextra -Wpedantic <-- that should flag i think any of these weird practices. As you stated tho, i'd be keen to learn why i am wrong! |
Arrays aren't the best example, since they are inherently about linear, scalar offsets, but you might see a negative offset from the start of a (decayed) array in the implementation of an allocator with clobber canaries before and after the data.