Re: strlen(), K+1: clarification



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
.



Relevant Pages

  • Re: strlen(), K+1: clarification
    ... objects that did not overlap 100%. ... the behavior of memcpy and confusing && and || under pressure, ... three multiple choice answers at once, ...
    (comp.programming)
  • Re: Yes, IE7 has tabs!
    ... >> The tabbed browsing experience in the upcoming IE7 beta is pretty basic. ... >> Expect additional end-user functionality to come in after the beta.... ... >> Some people have asked why we didn't put tabs in IE sooner. ... Is it confusing if IE has tabs, ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Is it possible to use the value of the PROGRAM ID within the source code?
    ... >> One of my favorite programming books. ... >Mr Wagner, this not confusing, at all. ... When functionality changes, OO shines brightest. ... >data collection terminals. ...
    (comp.lang.cobol)
  • Re: Wrapping input button with A tag: OK?
    ... You don't need to mislead people into confusing buttons ... I want to know about downside risks: ... the inner element's functionality, or the outer element's, or both ... It is valid (even in HTML 4.01, though with a meaning different from ...
    (alt.html)
  • Re: Wrapping input button with A tag: OK?
    ... You don't need to mislead people into confusing buttons with links. ... I want to know about downside risks: ... It is valid (even in HTML 4.01, though with a meaning different from XHTML), but this does not imply that some meaning or specific functionality has been assigned to it. ...
    (alt.html)