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
Prefer fixed-width integer types over fundamental types like unsigned int
.
#2325
Comments
Starting off with |
I want to help with this. Is there any guideline in which cases to use which types? Let's say there is an |
We haven't yet made a decision about whether or not we want to do this so there is as of yet no work to do. |
I've thought about this more and think that focusing on changing Beyond that I think the marginal value diminishes quickly so I probably won't push on this issue much farther. |
Looking a bit around, it seems that if one doesn't have a reason for a specific fixed-width integer, it's more recommend to just stick with For indexes and "countable" things, I think it makes sense to prefer |
https://www.stroustrup.com/JSF-AV-rules.pdf The JSF Coding Guidelines written by C++'s inventor Bjarne Stroustrop recommended as far back as 2005 to avoid using variable-length integer types and provides some argument for doing so. This makes me feel even more confident that we don't need to keep using things like |
I wouldn't put too much weight on just one guideline, especially if it was for a very specific industry (jet fighters) and predates C++11 by a lot, even if it's "from the C++'s inventor". There are plenty of other guidelines out there that go in other directions. It's always easy to pick one example and argue why it's the "correct" source of truth. In the end our decision should be based on our needs/targets and not just because someone defined it for their objectives. IMHO, as long as we don't have a reason for a fixed-width integer type, it's better to let the compiler pick the actual type and it can be argued would also be the "most efficient" type for that architecture. |
Closing due to lack of enthusiasm from the team. I still think this issue has value but we need to triage for v3 and this isn't important enough to make the cut. Maybe in v4 we can reconsider our use of variable-width ints in our APIs. |
Subject of the issue
Many interfaces and class members use
unsigned int
. This type was seemingly picked as a C++03 shorthand forstd::size_t
or at least an approximation forstd::uint32_t
even thoughunsigned int
isn't necessarily 32 bits wide. If our intent is to use 32 bit (or 64 bit) unsigned integers, let's use a type which better expresses and guarantees our intent.A similar argument could be used for any uses of
short
,int
, orlong
although are not nearly as pervasive in the interface so I'm not necessarily calling those out.See this cppreference page for more information on the various possible widths of integral types.
The text was updated successfully, but these errors were encountered: