logoalt Hacker News

rwmjtoday at 9:21 AM2 repliesview on HN

Slighty off-topic, why is he using ptrdiff_t (instead of size_t) for the cap & len types?


Replies

r1chardnltoday at 9:43 AM

From one of his other blogposts. "Guidelines for computing sizes and subscripts"

  Never mix unsigned and signed operands. Prefer signed. If you need to convert an operand, see (2).
https://nullprogram.com/blog/2024/05/24/

https://www.youtube.com/watch?v=wvtFGa6XJDU

show 1 reply
rurbantoday at 12:24 PM

Skeeto and Stroustrup are a bit confused about valid index types. They prefer signed, which will lead to overflows on negative values, but have the advantage of using only half of the valid ranges, so there's more heap for the rest. Very confused