Comment by uecker
8 days ago
BTW: I was experimenting a bit more with string and string view (strv) types in my e toy library: https://codeberg.org/uecker/noplate/
The tests are maybe better examples than those on godbolt. https://codeberg.org/uecker/noplate/src/branch/main/tests/st...
How does strv2cstr work? I assume it doesn't allocate, so not sure how it can add a null terminator.
It will not add one if there isn't one already. (I should probably rename this function, work in progress..). But the type is an array of the correct length.
Edit: renamed to strv2array
Ah, okay. In that case I feel like the only sane way to approach this is to completely abolish null-terminated strings, and reimplement everything (including stuff like printf's format and arguments) in terms of strv. Otherwise if there has to be a 2cstr function, it should be an allocating one.
1 reply →