-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Unclear is offsetting one element past array length is allowed #138969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As far as I know, while the documentation states that pointers must be within the bounds of the allocated object (a < base + size), there is indeed a special case: "one-past-the-end" pointers are explicitly allowed. "One-past-the-end" pointers are crucial for iteration, allowing representation of the end of a valid range. It enables more natural range checking and pointer arithmetic implementations. Maybe the documentation should be improved. |
@rustbot claim |
@rustbot label: +T-opsem +T-libs-api +A-raw-pointers |
No, you misunderstood. The "offset" docs are very explicit about this: If you do |
Explain one-past-the-end pointer in std library Closing rust-lang#138969 r? libs
Rollup merge of rust-lang#138976 - xizheyin:issue-138969, r=RalfJung Explain one-past-the-end pointer in std library Closing rust-lang#138969 r? libs
Explain one-past-the-end pointer in std library Closing rust-lang#138969 r? libs
Location
https://doc.rust-lang.org/std/primitive.pointer.html#method.offset
Summary
Offset doc states that
allocated object doc states that
so as i understand offsetting pointer to the head of an array one past it's length should not be allowed, but in practice it is allowed
this code compiles just fine, but this one produces an error
The text was updated successfully, but these errors were encountered: