3 ms·
> I'm curious what the motivation was to use int instead of uint considering indexes cannot be negative in Go. I want to emphasize that I do not know the true
by nordsieck 8y ago
> I'm curious what the motivation was to use int instead of uint considering indexes cannot be negative in Go.
I want to emphasize that I do not know the true answer to this question.
I think that indexes are int to play nicely with a decrementing loop counter. Doing:
for i := len(n) - 1; i >= 0; i-- { fmt.Println(n[i]) }
requires i to be signed due to the last iteration.
- a1369209993 8y agoI'm not sure about go, but in C this could be: for(size_t i = zn; i-- > 0 ;) printf("%s\n",n[i]); (This is a large part of why unsigned over/underflow is well-defined behavior in C.)
- nordsieck 8y agoIn Go, i++/i-- is a statement, not an expression, so that doesn't work. More generally, assignment is always a statement, and never an expression (e.g. you can't say a = b = c)