Skip to content
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

Clarify (un)signed-ness of pointers for comparisons #77497

Closed
gamozolabs opened this issue Oct 3, 2020 · 1 comment · Fixed by #136364
Closed

Clarify (un)signed-ness of pointers for comparisons #77497

gamozolabs opened this issue Oct 3, 2020 · 1 comment · Fixed by #136364
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-raw-pointers Area: raw pointers, MaybeUninit, NonNull C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@gamozolabs
Copy link

It seems currently pointer comparisons, ala. (foo as *const u32) > (bar as *const u32). Emits an unsigned comparison. I looked a little bit to see if this was documented somewhere and I didn't see anything super obvious.

Is this something that is defined behavior, and if it is, could we clarify it in the primitive pointer type documentation? This can be relevant especially in many kernel designs when there are "negative" addresses in the kernel and "positive" in user-space.

Thanks!
-B

@gamozolabs gamozolabs changed the title Clarify (un)signed-ness of pointers Clarify (un)signed-ness of pointers for comparisons Oct 3, 2020
@jonas-schievink jonas-schievink added A-raw-pointers Area: raw pointers, MaybeUninit, NonNull C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Oct 3, 2020
@RalfJung
Copy link
Member

RalfJung commented Oct 5, 2020

Yes, pointers are definitely treated as unsigned integers for inequality comparisons. There is no such thing as a "negative address", just an address >= 0xF0000000[00000000].

@Enselic Enselic added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Dec 6, 2024
@bors bors closed this as completed in 15a5f5f Feb 1, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 1, 2025
Rollup merge of rust-lang#136364 - hkBst:ptr_cmp_docs, r=tgross35

document that ptr cmp is unsigned

Fixes rust-lang#77497
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-raw-pointers Area: raw pointers, MaybeUninit, NonNull C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants