3 ms·
Still, unless you're writing something that has to be very low-level all the way through, it's better to use a string-handling library than the stdlib tools for
by cestith 6y ago
Still, unless you're writing something that has to be very low-level all the way through, it's better to use a string-handling library than the stdlib tools for strings.
- stefan_ 6y agoThe first thing you do is not use any strings. You'll be amazed how much you can get done in languages that aren't so obsessively centered around stringified programming.
- derefr 6y agoYes, sure, write Unix CLI plumbing tools without strings.
- pjc50 6y agoUntil you want to communicate with the user, filesystem, or web.
- Animats 6y agoIt was a design decision of QNX that the kernel never uses strings. Everything the kernel handles is fixed length, except messages, and messages go from one user process to another. The kernel does not allocate space for them. I think they go that right. There's a QNX user process that's always present, called "proc", which handles pathnames and the "resource managers", programs which respond to path names. But that's in user space, and has all the tools of a user-space program.
- cestith 6y agoThere are absolutely things that can be written without string handling. Then again, there are things that can't. Not handling strings in the kernel probably was a good decision. That userland I'll bet has string handling though, to be useful to users.
- cestith 6y agoMost of the code I write has a spec of input and output being some form of text. Still, I tend to write that in languages that have safe string handling and drop into C only when the profiler indicates that's useful. When handling strings in C, it's useful to use the string functions from glib or pull in one of the specifically safe string handling libraries and not use any C stdlib functions for strings at all. There are a number of C strings libraries safer to use than the standard library, and many of them are simpler, more feature-rich, or both. * https://github.com/intel/safestringlib https://github.com/intel/safestringlib (MIT licensed) * https://github.com/rurban/safeclib https://github.com/rurban/safeclib (MITish) * https://github.com/mpedrero/safeString https://github.com/mpedrero/safeString (MIT licensed) * https://github.com/antirez/sds https://github.com/antirez/sds (BSD 2-clause, and gives you dynamic strings) * https://github.com/maxim2266/str https://github.com/maxim2266/str (BSD 3-clause) * https://github.com/xyproto/egcc https://github.com/xyproto/egcc (GPL 2.0, includes GC on strings) * https://github.com/composer927/stringstruct https://github.com/composer927/stringstruct (GPL 3.0) * https://github.com/c-factory/strings https://github.com/c-factory/strings (MIT licensed) * https://github.com/cavaliercoder/c-stringbuilder https://github.com/cavaliercoder/c-stringbuilder (MIT licensed, does dynamic) If one does use the C standard library directly for handling strings, the advisories from CERT, NASA, Github, and others should be welcome advice (CERT's advice, BTW, includes recommending a safer strings library right off).