3 ms·
Yes it would, because this is basically string processing where C is the worst possible language one could use. I've detailed in another comment how std::string
by blub 11y ago
Yes it would, because this is basically string processing where C is the worst possible language one could use. I've detailed in another comment how std::string could be used.
- joushou 11y agoYou're talking about naked char[]. You can just as easily make a struct{ int len; char* str; } in C, and combined with the "n" variants of string operations, would work just fine with common tools. Again, C++ does not make anything safer, and its types can easily be replicated in any other language.
- kccqzy 11y agoI believe this is called pascal style strings and GCC has builtin support for it.
- pjmlp 11y agoBeing possible, doesn't mean the majority of C developers make use of it. The "n" variants are a joke in terms of security, even the C99 annex, that was demoted to optional in C11. I call them a joke, because tracking the pointer and length separately is hardly an improvement in terms of security. The only improvement that the "n" variants added is that the null character is always added to the end, instead of how strncpy does it, by only adding the character if there is enough space.
- NoGravitas 11y agoYou could stay in C and use glib strings.