Y
Hacker News
new
|
ask
|
show
|
jobs
by
phkahler
1400 days ago
I'd argue that is a terrible way to write it since it depends on the rollover to terminate. Using i >= 0 is less mental work but also requires that i be signed.
2 comments
ghoward
1400 days ago
Rollover on unsigned ints is well-defined in C.
link
hbn
1399 days ago
I think their point is that it's less well defined in the average human's brain
When most people see 0 - 1 they don't immediately think 11111111111111111111111111111111
link
ghoward
1399 days ago
We're talking about C, though. I hope the average human is
not
writing C.
link
jcelerier
1399 days ago
the average person writing C is absolutely an average human in terms of relationship with mathematics
link
xdavidliu
1400 days ago
if we used i >= 0 and someone were to come in and change "int i" to "unsigned i" or "size_t i", the result would be catastrophic
link
Leherenn
1400 days ago
The same argument can be applied to GP's code with the added bonus it will cause UB at some point.
link