(Too) Much Ado About Nothing (Re(ally): Strings?)

Gary Bisaga x4219 gary at neptune.uucp
Sat Jun 29 03:52:44 AEST 1991


In article <3529 at unisoft.UUCP> greywolf at unisoft.UUCP (The Grey Wolf) writes:
>/* <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.  ...
>
>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,
                                                     ^^^ System call? (I know,
                                                     picky picky)
>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!*
Why even bother EVER referring to the start of the string?  Why not
always use pointers to the end of strings to refer to them?  The length
would be stored at that location, and the [] operator would be changed
accordingly.  Or better yet, change the C compilers so that a (char *)
is actually a 64-bit pointer that holds BOTH the start and end of the
string!  The drawback, of course, is that most string handling routines
would need to use unions or be written in assembly language to handle
strings, or the compiler would need to be further modified to recognize
as builtins functions like strlen, but this seems a small price to pay
for the increased functionality.

In spite of this, I do agree that returning the start of the string is
useless.  It would be much more useful instead to return a pointer to
the start of the global shared-segment pointer table, unless you have
an inverted page table machine, in which case it wouldn't return anything.



More information about the Comp.unix.internals mailing list