Re: strlen(), K+1: clarification
- From: amorgan@xxxxxxxxxxxxxxxxxx (Alan Morgan)
- Date: Tue, 26 Feb 2008 11:44:22 -0800 (PST)
In article <WLCdnST6Sf3h-FnanZ2dnUVZ8qugnZ2d@xxxxxx>,
Richard Heathfield <rjh@xxxxxxxxxxxxxxx> wrote:
Alan Morgan said:
<snip>
Heavens to Knuth, you rake a guy over the coals for brain farting and
confusing && and ||
You have been spinozed. I didn't confuse them at all. I *misread* one of
the answers in the multiple choice. Mr Nilges's continuous repetitions of
falsehoods do not make those falsehoods true. I have made this distinction
a number of times.
My apologies. I didn't remember the details (and shouldn't have trusted
Nilges). I did recall that the error was of the "brain fart/not paying
attention" and not of the "doesn't know the difference" variety.
As Richard unintentionally demonstrated,
using memcpy means you need to check for overlap yourself to avoid a
bug.
Wow. They should really document that somewhere...
Um, quite so. But of course I simply didn't consider the overlapping case,
because it didn't occur to me that anyone would want to swap overlapping
objects that did not overlap 100%. On reflection, I thought they might, so
I mentioned the fact. Everyone else seems to have reacted to this by
saying "hmmm, no, actually that would be dumb because..." - except one
person, of course.
And saying "Hmm, I might have overlooked this case" is, of course, what
an intelligent and honest programmer would do. Concluding that you didn't
need to change anything is just icing on the cake.
struct TYPstring
{
long intLength;
char * strValue;
}
with an inspect function to make sure that the value is the length
claimed. It is obscene that this has to be done, but that's C for you.
I don't see this as a major improvement.
Neither do I. But I /do/ see { size_t length; size_t capacity; char *data;
} as a major improvement (given sufficient supporting functionality, of
course).
Sure (and I dismissed the original TYPstring too cavalierly. It does
improve strcat and strcpy from O(n+m) to O(m), as a moment's thought
should have told me). Alas, I think that "sufficient supporting
functionality" includes language changes and not just library changes
in order to make string usage fun-n-easy. I really wish C had a "real"
bounds-checked, auto-sizing, garbage collected string type. It would
stick out like a sore thumb alongside the rest of the language, but
it would make a lot of code so much easier to write (insert "If you
want FEATURE X you know where to find it").
Alan
--
Defendit numerus
.
- References:
- strlen(), K+1: clarification
- From: spinoza1111
- Re: strlen(), K+1: clarification
- From: spinoza1111
- Re: strlen(), K+1: clarification
- From: Alan Morgan
- Re: strlen(), K+1: clarification
- From: Richard Heathfield
- strlen(), K+1: clarification
- Prev by Date: Re: strlen(), K+1: clarification
- Next by Date: Re: strlen(), K+1: clarification
- Previous by thread: Re: strlen(), K+1: clarification
- Next by thread: Re: strlen(), K+1: clarification
- Index(es):
Relevant Pages
|