logoalt Hacker News

wahern • today at 5:24 AM • 3 replies • view on HN

Not everybody recommends size_t. There's a sizeable community of people absolutely convinced most integers, including length and capacity integers, should be signed. And they stick to their guns even for C and C++. They have some very compelling logical arguments on their side, but IMO in languages like C and C++ they're just fatally unrealistic.


Replies

ozgrakkurt • today at 8:15 AM

This is anachronistic imo. There is no point of using signed or larger than needed integers when programming in a modern way.

You have fuzzing, test coverage checks, overflow checks, static analysis, llm review. There is no conceivable reason why you might have a problem with using an u16 for a buffer length.

Even reading the PR comments shows that these libraries are just really low quality.

They are discussing if they should check the error return on callsites now that they made a function fallible.

Even a library like openssl using raw arithmetic operators all over the place is just weird imo. Every arithmetic operation should be checked version of the operation unless there is a provable performance hit. Languages should just not have operators

uecker • today at 6:04 AM

Why unrealistic? I was in the unsigned camp a long time ago and switched to signed types for indexing and sizes, and this made many problems go a way.

There was just a nginx issue that highlights how problematic the use of unsigned is in this context: CVE -2026-123007

➕ show 2 replies
jurf • today at 7:40 AM

ssize_t