strings

Mark A Terribile mat at mole-end.UUCP
Sun May 14 16:35:15 AEST 1989


> >>C says that a string is terminated with a '\0' byte.  ...  C programmers
> >>assign a '\0' byte, so the implementation of C library routines can never
> >>be speeded up.  For other languages, [implementations are often improved].
 
> >Improvements to C library routines are quite possible.  Like all such,
> >cleverness is sometimes required.  ...
 
> How do you improve a C library routine to look in a string descriptor to
> just grab the current length of the string?  In other languages, libraries
> can do that.  ...

Or the compilers can emit code ...

> ...  It kind of seems to me that if a C library does that, [ it will ] break
> my legal C program.  On the other hand, [ strlen() ] has to scan every byte
> of ... my 300K ... or my 509-byte array ... several thousand times.  It seems
> intrinsically worse to me.

Well, in C you are stuck.  At the risk of being told to go to my own group,
this is the point where you should switch to C++ and define a string type
that uses whatever you have available in your particular environment.  Just
derive it (compatibly) from an existing string type so that if you have to
run in a pure-C++ environment, you have a fallback.   Oh, and where a compiler
would emit code, you can make C++ use inlines.

Of course, I could ask you to show me a machine on which the FORTRAN compiler
has access to the internal implementation of COBOL, or on which COBOL can be
made to use the FORTRAN complex arithmetic algorithms.  We could go on.
-- 

 (This man's opinions are his own.)
 From mole-end				Mark Terribile



More information about the Comp.lang.c mailing list