4 ms·
In C you have char*
by groundzeros2015 7mo ago
In C you have char*
- kccqzy 7mo agoAnd the type system does not tell you if you need to call free on this char* when you’re done with it.
- groundzeros2015 7mo agoCorrect. Haphazardly passing ownership of individual nodes around is a C++ and OOP anti-pattern.
- pjc50 7mo agoIn C you only have char*.
- tosti 7mo agowchar exists. (And the possibility to implement whatever you want, ofc.)
- groundzeros2015 7mo agoYou can compose char* in a struct.
- rcxdude 7mo agoWhich isn't very good for substrings due to the null-termination requirement.
- groundzeros2015 7mo agoStruct Substring { char start, end }; My point is ownership being transferred implicitly in a struct assignment is a complexity introduced by C++. In C the concern of allocating memory and using it is separate. String_view is attempt to add more separation. But C programmers were already there.
- rcxdude 7mo agoWell yeah, and you could always do the same thing in C++, but having a standard structure for it makes interoperability a lot easier.
- 1718627440 7mo agoAn object of type char * isn't necessarily null-terminated.
- rcxdude 7mo agoNo, but that makes it no longer a string as far as most C functions are concerned.
- guenthert 7mo agostrtok() happily punches those holes in. Now you could argue, the resulting strings, while null-terminated, aren't true substrings (as the origin string is now corrupted), but in the context of parsing (particularly here using white-space as delimiter), that wouldn't be much an issue.