# \`Indexer\` and \`Int\` vs \`UInt\`

**URL:** <https://forum.modular.com/t/indexer-and-int-vs-uint/2210>\
**Category:** Standard Library\
**Created:** [September 2, 2025, 3:48am UTC](https://forum.modular.com/t/indexer-and-int-vs-uint/2210 "2025-09-02T03:48:21Z")\
**Posts on this page:** 1\
**Showing post:** 107

<div class="post-metadata">

**Author:** ![clattner](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/clattner/32/201_2.png) [@clattner](https://forum.modular.com/u/clattner)\
**Post date:** [September 10, 2025, 6:28pm UTC](https://forum.modular.com/t/indexer-and-int-vs-uint/2210/107 "2025-09-10T18:28:35Z")

</div>

> [@yinon](#):
>
> Are you saying that only `UnsafePointer` should use `Indexer`, i.e. `List. __getitem__ ` will just support `Int`?

Yes, that’s exactly what I’m suggesting. The use of `Indexer` should be exceptionally rare, used by low-level code like UnsafePointer, but not by common application level types like List.

> [@yinon](#):
>
> What about negative Indexing runtime performance overhead? Swift doesn’t have negative indexing right?

There is an active discussion about what to do about that. I’m not sure the final outcome and I believe the discussion hasn’t converged, but I find it likely that it will be removed entirely. It is an active performance problem for signed types as you say, and signed types aren’t going away even if unsigned types were to be allowed.

> [@yinon](#):
>
> What about ergonomics if I’m using `UInt` indexes I will have to explicitly cast them into an `Int` every time I index into a `List`, `Span`, …

The point is that you shouldn’t be using `UInt` for random integer values that are positive-only. Where did you get something of `UInt` type if everything returns Int.

> [@Nick](#):
>
> I think this the example you’ve been waiting for @clattner. You say Swift hasn’t suffered from making the default `Int` type a platform-specific size, but Swift (like Go) is only used on 64-bit platforms in practice, so I wouldn’t expect many people to have battle-tested just how portable Swift code is.

That’s not the case: Apple watch is 32-bit (specifically “ILP32” where `sizeof(Int)` and `sizeof(pointer)` is 32-bit), even when the CPU is 64-bit ([more nerdery if you’re interested](https://www.reddit.com/r/apple/comments/9kk5bd/apple_watch_apps_instantly_went_64bit_thanks_to/)). Beyond that, Swift has other supported (now obsolete) 32-bit devices. Swift also supports 32-bit linux and other systems.

> [@Nick](#):
>
> What should happen when a Mojo program/library contains a statement such as `var world_population = 8142000000`? Is that program/library going to compile and behave correctly all platforms?

The answer is no, the behavior changes, just like when you use `ssize_t` in C/C++. This isn’t related to the discussion or Int vs UInt though - `UInt` has the same behavior just at different thresholds.

-Chris

---

_[View the full topic](https://forum.modular.com/t/indexer-and-int-vs-uint/2210)._
