I saw very often iterations of an array using simple pointer arithmetic even in newer C ++ code. I wonder how safe they are, and if it's a good idea to use them. Consider this snippet (it also compiles in C if you newput it instead calloc):
int8_t *buffer = new int8_t[16];
for (int8_t *p = buffer; p < buffer + 16; p++) {
...
}
Will such an iteration not overflow, and the cycle will be completely skipped when it bufferbecomes distributed by address 0xFFFFFFF0(in a 32-bit address space) or 0xFFFFFFFFFFFFFFF0(64 bits)? As far as I know, this would be an extremely unfortunate, but still possible circumstance.
source
share