This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 999
Use int for containers #2940
Labels
Comments
C# uses int for sizes https://docs.microsoft.com/en-us/dotnet/api/system.array.length?view=net-6.0 |
Bjarne Stroustrup recommeds use signed types for sizes: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1428r0.pdf |
1vanK
added a commit
that referenced
this issue
May 23, 2022
This was referenced May 23, 2022
1vanK
added a commit
that referenced
this issue
May 24, 2022
1vanK
added a commit
that referenced
this issue
May 24, 2022
This was referenced May 27, 2022
1vanK
added a commit
that referenced
this issue
May 28, 2022
1vanK
added a commit
that referenced
this issue
May 29, 2022
This was referenced May 30, 2022
1vanK
added a commit
that referenced
this issue
Jun 6, 2022
This was referenced Jun 6, 2022
Merged
This was referenced Jun 8, 2022
1vanK
added a commit
that referenced
this issue
Jun 8, 2022
1vanK
added a commit
that referenced
this issue
Jun 18, 2022
Marking this stale since there has been no activity for 30 days. |
1vanK
added a commit
that referenced
this issue
Jun 26, 2022
Merged
1vanK
added a commit
that referenced
this issue
Jul 11, 2022
This was referenced Aug 27, 2022
This was referenced Sep 25, 2022
This was referenced Nov 7, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
We use
unsigned
to store sizes and indices.If user write
size1 - size2
, then overflow occurs ifsize1 < size2
.Those, sizes still need to be converted to
int
before being used in calculations, and user can easily forget about itCycle
for (unsigned i = 9; i >= 0; i--)
will never stop, becausei >= 0
is always true.User can workaround this in many ways, but why? Again, this is an additional source of error.
We disable warning to allow using cycles like
Scott Meyers recommeds use signed types in interfaces https://www.aristeia.com/Papers/C++ReportColumns/sep95.pdf
Bullet uses int for capacity & size & indices https://github.com/urho3d/Urho3D/blob/master/Source/ThirdParty/Bullet/src/LinearMath/btAlignedObjectArray.h
Related: #2939
The text was updated successfully, but these errors were encountered: