Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Use int for containers #2940

Open
1vanK opened this issue May 19, 2022 · 3 comments
Open

Use int for containers #2940

1vanK opened this issue May 19, 2022 · 3 comments

Comments

@1vanK
Copy link
Contributor

1vanK commented May 19, 2022

We use unsigned to store sizes and indices.
If user write size1 - size2, then overflow occurs if size1 < size2.
Those, sizes still need to be converted to int before being used in calculations, and user can easily forget about it

Cycle for (unsigned i = 9; i >= 0; i--) will never stop, because i >= 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

void Audio::UpdateInternal(float timeStep)
{
    URHO3D_PROFILE(UpdateAudio);

    // Update in reverse order, because sound sources might remove themselves
    for (u32 i = soundSources_.Size() - 1; i < soundSources_.Size(); --i)
    {

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

@1vanK
Copy link
Contributor Author

1vanK commented May 19, 2022

@1vanK
Copy link
Contributor Author

1vanK commented May 19, 2022

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
1vanK added a commit that referenced this issue Jun 2, 2022
1vanK added a commit that referenced this issue Jun 4, 2022
1vanK added a commit that referenced this issue Jun 6, 2022
This was referenced Jun 6, 2022
1vanK added a commit that referenced this issue Jun 7, 2022
1vanK added a commit that referenced this issue Jun 7, 2022
1vanK added a commit that referenced this issue Jun 8, 2022
@github-actions
Copy link

Marking this stale since there has been no activity for 30 days.
It will be closed if there is no activity for another 15 days.

@github-actions github-actions bot added the stale label Jun 19, 2022
@1vanK 1vanK added backlog and removed stale labels Jun 19, 2022
1vanK added a commit that referenced this issue Jun 26, 2022
1vanK added a commit that referenced this issue Jun 27, 2022
1vanK added a commit that referenced this issue Jun 28, 2022
1vanK added a commit that referenced this issue Jul 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant