4 ms·
> changing a pointer that points into an object so that it points into another object invokes undefined behavior Do you have a source for this? Couldn't find a
by MaxBarraclough 4y ago
> changing a pointer that points into an object so that it points into another object invokes undefined behavior
Do you have a source for this? Couldn't find anything on it with a quick web search.
- Someone 4y agohttps://en.cppreference.com/w/cpp/language/operator_arithmetic https://en.cppreference.com/w/cpp/language/operator_arithmet...: “If the pointer P points to the ith element of an array, then the expressions P + n, n + P, and P - n are pointers of the same type that point to the i+nth, i+nth, and i-nth element of the same array, respectively. The result of pointer addition may also be a one-past-the-end pointer (that is, pointer P such that the expression P - 1 points to the last element of the array). Any other situations (that is, attempts to generate a pointer that isn't pointing at an element of the same array or one past the end) invoke undefined behavior.”
- MaxBarraclough 4y agoI think you may have misread my comment, that wasn't the part I was referring to.