(Too) Much Ado About Nothing (Re(ally): Strings?)
The Grey Wolf
greywolf at unisoft.UUCP
Wed Jun 19 10:16:17 AEST 1991
/* <2883 at mccuts.uts.mcc.ac.uk> by zzassgl at uts.mcc.ac.uk (Geoff Lane)
*
* Arrrrrhhhhhhhhh......... NO NO NO. What you REALLY should do is
* prefix all strings with an expicit length. Look at the
* advantages - no more scanning down the bytes looking for the end - no
* more having to rewrite all the string handling routines because your
* particular project *must* have strings with embedded null bytes - no
* more forgetting about that final invisible byte and overwriting something
* vital.
*
Lessee, now...as I understand/perceive this one (I know we're not
looking for a debate here), given that most of the string routines
return a pointer to the beginning of the string which you've just
passed it, prefixing with an explicit length might not be a
terrible idea......nahhhhh.
I *do*, however, find it annoying that when you call something
like getwd(), gets()/fgets(), str[n]cpy(), str[n]cat(), et al.
they all return pointers to the *start* of the string, which you
just passed. Why couldn't they return a pointer to the *end* of
the string so that you don't have to go through all the bleeding
overhead to find out yourself? Sure, it's just one system call,
but sometimes strcpy/strcat occur in tight loops, with the need to
know where the end of the string is (bad example, since strcat()
appends by default). This necessitates a strlen() call, or an
inline for(;;) loop to calculate it. *I ALREADY KNOW WHERE THE
START OF MY STRING IS! USING THAT AS A RETURN VALUE IS USELESS!*
*ARGH!*
* By the way, is this a 5 minute argument or a 10 minute argument?
regain_composure();
I told you once...
* --
* Geoff. Lane. Janet: zzassgl at uk.ac.mcc.cms
* UTS Sys Admin, Manchester Computing Centre, Oxford Rd, Manchester, M13 9PL
*/
More information about the Comp.unix.internals
mailing list