logoalt Hacker News

tialaramex • today at 12:34 AM • 0 replies • view on HN

Yeah, this is just C doesn't have fat pointers. Fat pointers were proposed for C89. In some alternate universe C89 has fat pointers and in that universe probably by now many of the weird 0-terminated APIs we're frustrated by work on fat pointers instead and we're all better off for it.

A fat pointer is one ordinary thin pointer, plus a pointer-sized blob of extra information, commonly a length. Examples would be Rust's &[T] slice reference, its &str string reference and a pointer for dynamic dispatch &dyn Shape in which that extra blob is pointing to a v-table of functions for how this particular type implements the Shape trait.