@steveklabnik posed the question: What should we be suggesting at the type to use by default in the Guide for integrer valued things (Rust Issue #15526).
Meanwhile, in the discussion about putting integer fallback RFC PR 212 back in, part of the argument during the team meeting for why we need a by-default fallback (as opposed to one you opt into via a scoped attribute) was that int
, as in the type named “int” (whatever that may be), will be the type that people expect as the default, ending with: “if int
has the wrong size [then] that’s a different discussion.”
So, okay, let us have that discussion somewhere then. Maybe on this discuss thread.
The fact that the integer arithmetic type that most everyone will reach for at first (int
) is the one that is inherently platform dependent is troubling to me.
Note that this is distinct from concerns about the presence of a fallback. I actually do find the “Lack of bugs” argument from RFC PR 212 persuasive. But that is only dicussing the cases where no type annotation nor i32
/i64
suffix is provided; it says nothing about the cases where the user wrote int
even though it is actually inappropriate to their problem domain.
Rust Issue #9940 was one take (with a very long attached discussion) on how to address this problem. Well, sort of: namely by renaming int
/uint
to something that made it clear that they are pointer-sized (and thus really only for use as indexes into objects in the address space). That RFC suggested intptr_t
/ uintptr_t
- Anyway, #9940 got closed because the person who filed the issue didn’t think the change was worth the trouble anymore.
You can read the arguments back-and-forth on the comment thread for #9940 and for RFC PR 212 about what the size of a default type should be (i.e. some people thought it should be fast, i.e. i32
, others thought we should discuss something less likely to under- or overflow, namely i64
).
I am sympathetic to both arguments; I wanted us to consider i64
as a default size, but I would not fight i32
if my only alternative is the platform-dependent size aka intptr_t
.
In any case, renaming the current int
to intptr_t
is probably not enough on its own, because I suspect the type names int
and uint
(and likewise the suffixes i
and u
) are too sweet to give up. So then, what do we use them for?
(See also related topic: Integer Types )