Hacker News
points by teo_zero 3 days ago | 0 comments
> I can't think of a single time where you DON'T know what `count` is

A string created by strdup().

[–] cowlevel 3 days ago
Then you know it's strlen+1
[–] teo_zero 3 days ago
So you don't know it: you must calculate it, via an expensive strlen().
[–] NekkoDroid 3 days ago
To be fair, that is a downstream effect of C's worst mistake (NUL terminated strings). Also, if every allocation you'd get is ptr+size you could just derive it by also copying the size.

Basically, the issue is C having unsized allocations and related not tracking string length.