3 ms·
> Everytime I see for(int i=0;...;i++) In this case, it makes absolutely no difference at all. It could be argued that writing unsigned int would make the code
by dkbrk 12y ago
> Everytime I see for(int i=0;...;i++)
In this case, it makes absolutely no difference at all. It could be argued that writing unsigned int would make the code slightly harder to read. That said, I like to use stdint.h and unint32_t would, I think, not have any drawbacks.
> there is lot of code out there with interfaces expecting signed ints even though they should using uint
That's not a good reason to not use unsigned integers, it's a zero-overhead cast from unsigned to signed (at the risk of overflowing into the negative).
- Joky 12y agoIt change the semantic on the loop bound, and thus what the compiler can/cannot do when optimizing the code. Using uint limits the optimizer...
- detrino 12y agoUsing int also limits the optimizer in some ways, for example division/modulo becomes more expensive. Every time I see someone mention the optimization argument for signed integers I ask for examples and I've yet see a good one.