On 2024-06-22 03:58:46 +0000, NRK wrote: > Sized strings > ------------- > > typedef struct { > uint8_t *s; // or you can use `(unsigned) char *` > ptrdiff_t len; // or you can use `size_t`, see explanation > below > } Str; > > * Cheap access to the string length which allows expressing string > operations much more naturally (read: less error prone). > * Zero copy sub-string. This is a huge one, because it avoids many > spurious copies and/or allocations.
This is OK if your string is constant. Otherwise, this may be dangerous, e.g. in case the full string is changed in place. -- Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)