Don't called them signed ints and unsigned ints. Call them ints and addresses.

Most of us don't care about the increased range of integers yielded by that final extra bit. But addresses sometimes need to set it. And we never want to think of addresses as negative.

· · Web · 2 · 1 · 2

uints are used pretty heavily in cryptography when you want to do modular arithmetic by exploiting the fact that they overflow in a reliable way, so I think they have more use cases than just addresses...

@cjd For sure! Makes sense to create a typedef in certain domains. But spreading that typedef too broadly really muddies things for most people.

@akkartik @cjd I always felt like ints should be unsigned by default because negative numbers are rarely useful. The “negative indicates error” gimmick in C drives me nuts. If I’m actually doing math I use floats.

@octesian I've tried that in the past. I found that in practice even things that seem unsigned like the size of an array have a way of infecting everything. If the size is unsigned, the index must be unsigned to compare cleanly to it in a loop. And if the index is unsigned, iterating in reverse order gets tricky. These days I do this in C++:



for(size_t i=data.size();i>0;){

@octesian I find that fiddly. But yeah, if you're disciplined it can work.

@octesian Though I really don't understand how negative numbers can be less useful than numbers >= 2^31. (I agree that using -1 as an error code suxxors hard. But it's not the first use of negative numbers that comes to mind.)

@akkartik it’s not a contest of most usefulness, it’s about least annoyance. I dislike them because most of the time negative numbers aren’t valid values yet I still have to validate function inputs to make sure someone didn’t pass in a negative by mistake. I’m curious where you’re finding all these uses for negative integers.

Sign in to participate in the conversation

Revel in the marvels of the universe. We are a collective of forward-thinking individuals who strive to better ourselves and our surroundings through constant creation. We express ourselves through music, art, games, and writing. We also put great value in play. A warm welcome to any like-minded people who feel these ideals resonate with them.