NSUInteger in reversed loop confusion?

≡放荡痞女 提交于 2019-12-02 09:56:12

An unsigned type can't "keep going into negative numbers". After the iteration when index = 0, index-- becomes 0xFFFFFFFF, which is still more than zero. Easy mistake to make, I've done it myself.

The static analyzer will actually warn you about this ("Condition index >= 0 is always true" or such like.) I highly recommend setting it to run automatically on debug builds.

Note that an NSUInteger is always >= 0, by consequence, your loop condition will always be true.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!