Re: Results of the memswap() smackdown from the thread "Sorting" assignment



On Feb 18, 12:56 am, "Clive D. W. Feather" <cl...@on-the-
train.demon.co.uk> wrote:
In article
<d44c43d4-8a37-41e5-b7b5-9fd6e7516...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
spinoza1111 <spinoza1...@xxxxxxxxx> writes

No it isn't.

     The strcpy function copies the string pointed to by s2 (including
     the terminating null character) into the array pointed to by s1. If
     copying takes place between objects that overlap, the behavior is
     undefined.

[If s1 or s2 are NULL, it's also undefined as stated elsewhere.]

C is globally wrong if this is so. No wonder Dijkstra refused to even
mention C.

Whatever the infantile disorder C says, copy(null, nonnull),
copy(nonnull, null) and copy(null, null) are each NOPs. DO THE MATH.

There is no "math". The first of these is clearly an error ("copy
something to nowhere") and the second are arguable ("copy nothing to
somewhere" and "copy nothing to nowhere").

No, there IS "math" here. You think there's none because you don't
know math or its history, therefore you repeat the Roman mistake of
thinking you don't need zero and because you don't know math, you
don't know that "zero" is a special case of something more general.

"Copy something to nowhere" could easily arise as a potential case,
for example, when no memory exists. It has to be defined in order to
speak of the possibility, but your type of code monkey prefers to let
things crash, and blame the victim, don't you?

Why do you suppose most instruction sets have NOPs?

I won't be reading the snide mockery you have started to post. Send me
email at spinoza1111@xxxxxxxxx if you have anything useful to say.

Consider strcpy("", "ABC").

Let's not, since that is undefined behaviour for a different reason.

How pleasant it must be to be on a standards team. If it makes you
think, it's undefined. And, you can *** all over people like Schildt
from your perch, can't you?



But:

    char buf [5] = "";
    strcpy (buf, "ABC");

is fine.

How pleasant it must to be on a standards team. You don't have to
maintain some 100,000 line program at 3:00 AM in which buf isn't so
conveniently defined but passed as a parameter as char* buf with no
indication of its length. Your program has to set buf to ABC but you
don't know if the space is long enough to hold four bytes and there's
absolutely no way of finding out, because Dennis Ritchie was too cool
to put the length in the string where it belongs.

A string with a length code can be safely assigned: a C string cannot.

And, you can *** all over people like Schildt from your perch.

Can't you.

Since this is a str function, the runtime
knows that the left hand string occupies one byte that must be
sacrosanct

It doesn't know anything of the sort. It knows that a four byte string
is to be copied into a buffer whose first character is a NUL.

How pleasant it must be to be a standards man. You get to create your
own preconditions and are not handed them with the injunction to fix
the code by tomorrow or else.

And, you can *** all over people like Schildt from your perch.

and that the right hand string occupies four. It should do
nothing, not treat the operation as undefined!

If you want a function that only copies where the destination holds a
longer string, you can write one. Here, I'll write it for you:

    bool nilges_strcpy (char *dest, char *src)
    {
        bool r = strlen (dest) >= strlen (src);

        if (r)
            strcpy (dest, src);
        return r;
    }

How pleasant the life must be in standards land. You can create
contrived and clumsy examples which don't work for cases you then call
undefined. You don't need to code

bool clive_strcpy(char **chrDest, char *chrSrc)
{
if (strlen(*chrDest) < (intLengthSrc = strlen(chrSrc)))
{
free(*chrDest);
if ((*chrDest = (char)malloc((intLengthSrc + 1) *
EXPANSION_FACTOR)) == null) return 0;
}
strcpy(*strDest, strSrc);
return 1;
}

You don't have to worry, when creating this, about taking time away
from a real application problem.

I haven't tested this code, but it's real: yours is a toy. How
pleasant life must be: if it's hard, it's undefined and somebody
else's fault.

And you can *** all over Schildt from your perch.


Contempt for the zero case was a marker in the original "infantile
disorder",

You have mixed up the "zero case" with the "null pointer case". They are
not the same.

["They" = Ritchie et.al.]

They couldn't stand using a string length code because IBM did so in
PL.I, so they "just had" to think of something kicky and trendy and
new, and they chose Nul to take the fall,

Ritchie was well aware of BCPL, which used counted-length strings with a
maximum length of 255. The *collegiate* thing to do would be to ask him

Not "collegiate", collegial.

why he chose a terminated representation instead, rather than accuse him
of - well, I'm not sure *what* you are accusing him of.

Straw man. Ritchie needed only to use an unsigned short to get strings
up to 64K. For longer strings, he could have developed a library
procedure to manage arrays of these strings. This was not done.
Instead, real, if anonymous, programmers had to do it and usually got
*** on, as you *** on Herb, for actually making C useful. The big
shots, who gave the talks and ruined the reputations, have now cashed
out, and many of the actual toolsmiths have no health insurance and no
retirement, since they were so busy quietly remedying the mess you
people made that their "real" tasks suffered.

The length code limitation is easily solved whereas Nul creates
countless problems when real data contains Nuls.

You're very good at making smartass remarks about other people and
excuses for C. But I am unimpressed with your technical competence.

I have had it with this ***. Richard will either take the sabbatical,
leave for good, or stay. If he takes the sabbatical or leaves, will
somebody please tell me, sending me email at spinoza1111@xxxxxxxxx

I will now take the promised two weeks off. My bad for looking at this
newsgroup. But I mean every word I say to you, sir: your failed
attempt to destroy Schildt was exemplary of the behavior of trend
setters and thought leaders who replace knowing their trade and its
social context by cults of personality, and anti-personality. You
worked on the standards team on behalf of compiler vendors who were
terrified of having to change their compilers and as in the sync point
mess you created, you showed nothing but contempt for real programmers
who had a right to think of P++ as an atomic operation.




--
Clive D.W. Feather                       | Home: <cl....@xxxxxxxxxx>
Tel: +44 20 8495 6138 (work)             | Web:  <http://www..davros.org>
Fax: +44 870 051 9937                    | Work: <cl....@xxxxxxxxx>
Please reply to the Reply-To address, which is:  <cl...@xxxxxxxxxx>

.


Quantcast