12 ms·
One of the things that hampers C is its string processing. By using a nul terminator, rather than an out of band length indicator (a la Pascal, Perl, Java) man
by Roboprog 15y ago
One of the things that hampers C is its string processing. By using a nul terminator, rather than an out of band length indicator (a la Pascal, Perl, Java) many string operations become a O(n) operation, where n = length of string, rather than a O(1). When running things such as cobbling up HTML templates and prepared SQL statements or evaluating DSLs, sucky string handling really starts to matter. Some would argue that it matters more than how fast you can calculate prime numbers or fibonacci sequences.
I've ranted about this before: http://roboprogs.com/devel/2009.12.html http://roboprogs.com/devel/2009.12.html
- cygx 15y ago> One of the things that hampers C is its string processing. That's not a language, but a library issue. String handling in C is only as sucky as the library you're using...
- Roboprog 15y agoKind of bound to the semantics, though. E.g. - memset( s, '\0', sizeof( s) ); s[ 0 ] = '\0'; You can of course create a library (e.g. https://github.com/roboprog/buzzard/blob/master/bzrt/src/bzrt_bytes.h https://github.com/roboprog/buzzard/blob/master/bzrt/src/bzr...) to support alternate implementations (as interpreters and VMs created in C must), but it's not really much like ANSI C anymore.
- jebblue 15y agoBig difference here between these two, check out a copy of "Deep C Secrets" by Peter van der Linden. This is ok, safe, complete, reliable: memset( s, '\0', sizeof( s) ); This yields the perception that it works, depending on what is going to make use of s later on, it could fail to do what you intended depending on how you use s: s[ 0 ] = '\0';