4 ms·
You never need to call strlen unless you are getting your inputs from a place that doesn’t give you a string length (such as stdin).
by IgorPartola 2y ago
You never need to call strlen unless you are getting your inputs from a place that doesn’t give you a string length (such as stdin).
- saagarjha 2y agoThat's most interfaces…?
- kevin_thibedeau 2y agoNot argv[].
- saagarjha 2y agoYou still need to call strlen on each element?
- eru 2y agoSo now you are arguing that by default your strings should come with a length? Great! If you want that, you might as well bake that length into the string type by default (and use a specialised type, perhaps a naked raw pointer into the string) for when you don't want to pass the length.
- deathanatos 2y agoSo which is it, then? Does keeping size separate "blows your CPU cache"¹ or not? You can't argue it does in one case (Rust) but not in your case… (And note that the representation you're responding to is not really a "header", in the same sense that the trailing null is a "footer". The representation does not require the length be contiguous with the data, but that's what upthread was trying to say in the first place.) ¹(it doesn't…)