Results of the memswap() smackdown from the thread "Sorting"assignment - Programming Languages

This is a discussion on Results of the memswap() smackdown from the thread "Sorting"assignment - Programming Languages ; On Sat, 16 Feb 2008 11:35:02 -0600, spinoza1111 wrote (in article <72bd36b6-3418-4341-947f-3978712b557a@s37g2000prg.googlegroups.com>): [color=blue][color=green] >> a) A legitimate example where you would intentionally do a memswap() >> operation on overlapping memory regions?[/color] > > My "inventory control" example: a computer, now, ...

+ Reply to Thread
Page 20 of 28 FirstFirst ... 10 18 19 20 21 22 ... LastLast
Results 191 to 200 of 274

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

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

    On Sat, 16 Feb 2008 11:35:02 -0600, spinoza1111 wrote
    (in article
    <72bd36b6-3418-4341-947f-3978712b557a@s37g2000prg.googlegroups.com>):
    [color=blue][color=green]
    >> a) A legitimate example where you would intentionally do a memswap()
    >> operation on overlapping memory regions?[/color]
    >
    > My "inventory control" example: a computer, now, not a human being, is
    > given a job ticket that specifies that shelves 100..150 be swapped
    > with shelves 148..200.
    >
    > The job ticket was issued in error, but let's say that we're working
    > for Federal Express and the corporate bias is to do large jobs fast.[/color]

    The correct response would be to fix the error.
    [color=blue]
    > Here, it would be better to proceed, to get on with the sensible part
    > of the job, which is to swap 100..147 with 151..200.[/color]


    [color=blue]
    > This would not be the best solution in all cases.[/color]

    Of course not.
    [color=blue][color=green]
    >> The review you complain about made /numerous/ reference to real
    >> technical errors.  Interestingly, when you attempted to "deconstruct"
    >> it, you got almost every single technical point wrong in your post.[/color]
    >
    > That's a lie, and I see you're back to the races.[/color]

    It is a brief summary of a thread that is in the archives.
    [color=blue]
    > You don't participate in coding since you might make a mistake[/color]

    Wrong. I post code here periodically on things that I am interested
    in. Unlike you, I don't have a need to post code constantly, and more
    to the point, erroneous code, simply because I am too lazy to test it
    and see what it does.

    Your method of posting a function (or something approximating one that
    may or may not even compile in any known language), then saying that
    "whatever it happens to do" is the correct implementation of some
    problem that wasn't even specified seems to be unique to you, and I am
    very glad of that.
    [color=blue]
    > I examined Clive's document, and I found that it was PADDED.[/color]

    You tried to do so, and failed to make a compelling case. Did I miss
    the arrival of people agreeing with you?
    [color=blue]
    > memswap for overlapping IS THE SWAP OF THE NON-OVERLAPPING PARTS.[/color]

    Aha. Convenient for you, but by no means could this be considered a
    generalized solution, it's merely a convention. One that should be
    documented. Much as the documentation for memcpy() points out a
    convention, and points to another function which might be suitable if
    that convention doesn't meet your needs.

    You will kindly point out how the original questioner specified your
    convention for an implementation of memswap(), and how Richard and
    others were in error by failing to meet this requirement.
    [color=blue]
    > When the total length of the overlap is zero, this definition reduces to
    > ordinary swap. This is a more powerful definition that does more work.[/color]

    You might as well say "when the sky is blue, then the sky is blue."
    Talk about PADDED.
    [color=blue][color=green]
    >> It seems highly likely that if you did try to overlapped memswap(),
    >> which wasn't listed at all in the original request, and if you had a
    >> formal set of rules to explain how it behave in the various subcases,
    >> then a byte-by-byte memswap_overlapped() and a block memcpy memswap()
    >> would be beneficial.  Now the issue remains, can you explain, formally,
    >> how that the former would be behave?
    >>[/color]
    > I have done so. I experimented with doing swap inside the overlapping
    > regions, and the results were as I have said deterministic but
    > "strange".[/color]

    So your definition of a working solution, that you would "declare
    victory" over, is "strange"?
    [color=blue]
    > Their "strangeness" wasn't for me a problem,[/color]

    Right, because that didn't get in the way of your conclusions. Did you
    ever ask, or even care, if your convention (which you didn't even know
    was an issue when you coded it, it's just a happy coincidence here) was
    valid for anyone else, or the original poster?
    [color=blue]
    > The showstopper is that IF you swap inside overlapping regions, the
    > swap of the swap doesn't restore the initial condition, and this is
    > part of the ordinary meaning of "exchange": you should always be able
    > to get your money back.[/color]

    Ah, so you don't have a solution for it after all. You have a
    workaround, which may or may not be useful in a generalized
    implementation.
    [color=blue][color=green]
    >> They were alluded to, and you missed them.  It was one of those tests
    >> you like to take, if you wish.  ;-)[/color]
    >
    > I don't have the time to read all posts, and, I believe you're lying,
    > again.[/color]

    A convenient piece of subterfuge we've seen before. Anytime a post or
    group of posts appear containing factual information to which you have
    no way to handle, you do one or more of the following:
    a) Announce a temporary leave of absence starting immediately.
    b) Demonstrate a bout of Turret's Syndrome
    c) Pretend that you didn't read the post(s).
    d) Start new threads to attempt to make it disappear due to
    signal/noise ratio issues.

    [the memcpy overlap issue][color=blue]
    > Heathfield clearly remembered this and posted it after he posted code.[/color]

    Go back and read the message which preceded the comments by Heathfield
    that you are referring to above.

    Note that I asked you a question, and implied that there was something
    potentially amiss in the implementations, but that I didn't expect they
    mattered much for a childish drag race competition. You ignored the
    question, even though I told you that it was evidence that I did not
    automatically fawn over Richard's code automatically. If you had been
    coherent enough to pay attention, you could have saved yourself a lot
    of trouble.

    One of the issues there was overlap, but since it wasn't a part of the
    original requirement, and since it can't even be done cleanly in all
    cases, as you yourself have later admitted, and since it could be
    covered in documentation, it didn't matter.

    It was you that seized upon this as yet another example of grasping at
    straws to try and salvage something from it all.
    [color=blue]
    > But if he knew it and did not disclose it when he posted the code he
    > is guilty of fraud...[/color]

    How so? The documentation for memcpy() is available. It is a known
    limitation. It would only be called a fraud by someone totally unaware
    of the issue in the first place.
    [color=blue]
    > at a minimum, academic fraud (insofar as this discussion is
    > not commercial, but academic in the informal sense).[/color]

    You missed a career as a standup comedian.
    [color=blue]
    > They post facto pretend to know things they did not know,[/color]

    No pretending was involved. I implied the existence of an issue
    directly, and even laid it out there for you like a slow pitch over the
    plate, all you had to do was take a swing at it.
    [color=blue]
    > Insofar as Heathfield is using this network to present himself as a
    > paid C "expert" it is mail fraud under UK and USA law.[/color]

    Then sue him. Put your money where your mouth is and see if anyone of
    legal standing agrees with you.
    [color=blue][color=green]
    >>  It's literally intuitively obvious to anyone that knows anything about
    >> memcpy().  [/color]
    >
    > So why didn't you jump on Heathfield's code?[/color]

    Why didn't you /read/ what I /wrote/? I put it there for you, and you
    ignored it.
    [color=blue]
    > As it happens, I taught the use of memcpy at Princeton University in
    > 1990 and I mentioned at the time that it does not handle overlap,
    > because this was part of the manual that was the textbook.[/color]

    But you forgot about it later, yeah, we know.

    [color=blue]
    > I intuitively was repulsed by Heathfield's use of memcpy() based on my
    > intuition that given its multiple and varied implementations, it
    > represented a risk...an unnecessary one.[/color]

    Your intuition was in the wrong direction. Your concern was about
    memcpy() not behaving as expected. This issue is about memcpy doing
    just what it is supposed to do.
    [color=blue]
    > I was proven right, and you and he are so embarassed by your childish
    > error that you now are participating in a cover up.[/color]

    What's to be embarrassed about? I clearly made reference to having
    some issues with the existing implementations, and you ignored them,
    then disappeared for a day or so, then came back and saw Richard's
    response, you jumped up and down and giggled, and complete forgot about
    wondering why he posted it in the first place.
    [color=blue][color=green]
    >> Your "answer" for how overlapped memswap should behave is "whatever my
    >> code happens to do".  Even a child would be embarrassed by such
    >> tactics.[/color]
    >
    > You are now colluding, probably by email, to cover up a mistake by
    > Heathfield[/color]

    The last time I sent an email to Richard was several years ago, to
    report a minor issue pertaining to a short piece of sample code in one
    of the early chapters of C Unleashed, which may or may not have been
    rolled into his errata listing for the book.

    I can't even imagine why I would need to "collude" or "cover up
    something" where I openly wrote that I believed some issues were
    present. Why cover up what you openly make reference to in your posts?

    [color=blue]
    > The pity of it is that you have something to offer, and then you
    > either fraudulently attempt to cover up Heathfield's mistake, or
    > have colluded with him from day one,[/color]

    You are very badly confused. Look at the time stamps on the posts.
    Notice that I told you that I had at issues (plural) with the existing
    solutions. I did this before Richard wrote anything about it afaik,
    and I even asked you if you cared to know what such issues might be.
    You ignored my question completely. All you had to do was let me know
    if you cared at all, or if you didn't care.

    Also note that I said that I didn't think the issues were particularly
    relevant to this thread, and I still don't. You are the only one that
    seems to think they represent some earth-shattering revelation.


    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw






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

    spinoza1111 <spinoza1111@yahoo.com> writes:
    [color=blue]
    > On Feb 16, 11:27 am, Richard Heathfield <r...@see.sig.invalid> wrote:[color=green]
    >> Randy Howard said:
    >>
    >> <snip>
    >>[color=darkred]
    >> > I think this is hopeless, Clive.  Nilges doesn't see "broken" if his
    >> > code runs to completion.  Regardless what answer is spat out, if it
    >> > compiles and doesn't crash, he "declares victory".[/color][/color]
    >
    > In addition to confusing && and || last month, you posted code in
    > response to Malcolm without disclosing (perhaps not knowing) (perhaps
    > forgetting) that the failure of memcpy() to handle overlap in a
    > defined fashion meant that your solution was undefined for overlapping
    > blocks.[/color]

    This is very tiresome. Whatever the history, your clutching at this
    sort of straw looks foolish.

    --
    Ben.

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

    On Sat, 16 Feb 2008 12:05:11 -0600, spinoza1111 wrote
    (in article
    <37a2efad-2285-42d4-b0cd-bbf521d556c4@s8g2000prg.googlegroups.com>):
    [color=blue][color=green][color=darkred]
    >>> You're lying when you pretend that you knew about this problem,[/color]
    >>
    >> Read the article where I specifically mentioned there being an issue
    >> with the functions being discussed, and I asked if you would like to
    >> know what it was.[/color]
    >
    > That "issue" was raised after the code was posted. You and your friend
    > Heathfield are now claiming that you knew it all along.[/color]

    Quick question: How could I have told you about an issue with a piece
    of code until after I had seen it? How could I possibly have raised
    the issue /before/ it was posted? Am I supposed to have a crystal ball
    now?
    [color=blue]
    > I make errors in detail, to be sure.[/color]

    By the bucket.
    [color=blue]
    > I am less practised at C than Ben who is by far the best programmer here
    > (and whom you haven't had the decency or grace to recognize as such),[/color]

    If Ben wants to know my opinion of his programming abilities, all he
    has to do is ask me. He doesn't seem to clamor for attention (the
    positive or negative varieties) as you do.
    [color=blue]
    > You haven't contributed a single line of code.[/color]

    I saw no reason to do so. Someone else started this whole thing,
    asking about the ability to do something in C. Richard posted a
    function that would do what was asked about. It could have ended right
    there, and in my opinion, it likely should have, but some others posted
    alternative implementations which didn't fundamentally do any more to
    address the original question. Then you decided to turn it into a
    benchmark competition, and promptly screwed the first several attempts,
    didn't even test your code, didn't even post benchmarked code that
    actually tested the results, it up, and it all went downhill from
    there.

    Since the original question was answered, there doesn't seem to be any
    need for Yet Another Solution" to it.
    [color=blue]
    > Instead, you've
    > disrupted this and other threads constantly with unfounded statements
    > about the competence of others based not on evidence but on what
    > appears to be homophobia and poor anger management.[/color]

    Homophobia? Is your AFDB in need of replacement, or did I miss a memo?

    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw






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

    On Sat, 16 Feb 2008 12:45:21 -0600, Richard Heathfield wrote
    (in article <mf2dnWhZ-8fJsyranZ2dnUVZ8rednZ2d@bt.com>):
    [color=blue]
    > Clive D. W. Feather said [in reply to Ben, but presumably addressing Mr
    > Nilges]:
    >[color=green]
    >> If you think that's comparable to writing:
    >>
    >> for (i = 0; i < strlen (s); i++)
    >> // something that doesn't affect the value of or contents of s
    >>
    >> then you're even more deluded than we thought.[/color]
    >
    > No, he isn't - you just haven't known him long enough.[/color]

    You beat me to it.


    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw






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

    On Feb 17, 2:45 am, Richard Heathfield <r...@see.sig.invalid> wrote:[color=blue]
    > Clive D. W. Feather said [in reply to Ben, but presumably addressing Mr
    > Nilges]:
    >[color=green]
    > > If you think that's comparable to writing:[/color]
    >[color=green]
    > >      for (i = 0; i < strlen (s); i++)
    > >          // something that doesn't affect the value of or contents of s[/color]
    >[color=green]
    > > then you're even more deluded than we thought.[/color]
    >
    > No, he isn't - you just haven't known him long enough.[/color]

    Richard, please see my online petition for your removal from this
    newsgroup.

    Clive, in 2003, I used precisely the same code, and Richard initiated,
    enabled, and continually refreshed a campaign of personal destruction
    based on this which included written libel in the form of letters to
    Apress, my publisher. My book "Build Your Own .Net Language and
    Compiler" was nonetheless published, Apress having the good sense to
    ignore such malign letters, and this book has been often in the top
    fifty books on "compilers" at USA Amazon.

    You are getting sucked in to a Lynch mob. You hounded Schildt, and so
    the bullies want you on their team.

    What's really sad is that programming is still so much fun. I
    demonstrated a visual quicksort in C Sharp to my class today (far more
    than C could accomplish in reasonable time) which even for small
    arrays demonstrated dramatically the speed of quicksort which gave the
    lie to a crude claim made here that "I only see a difference, in C,
    for 1000 entries". The visual sort also demonstrated how toplevel
    entries in the interchange sort are quickly available.

    Here I have to see other people, good people, LEAVE after being
    assaulted, sometimes for having an obviously female, Hispanic, or
    African-American name, and I have to endure constant harassment in
    comp.programming (not, mind you, comp.lang.c) for not "drinking the
    Kool-Ade" on C.

    You wouldn't pull this shit in person. Like most people in cities
    today, you're probably too soft and too scared. Even the people who
    don't participate in the destruction are too soft and too scared to do
    other than make apologies for the clear bullies lest we all rock the
    boat.

    Please add your name, Clive, to my petition for the voluntary removal
    of Heathfield from this network.
    [color=blue]
    >
    > --
    > Richard Heathfield <http://www.cpax.org.uk>
    > Email: -http://www. +rjh@
    > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    > "Usenet is a strange place" - dmr 29 July 1999[/color]


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

    Ben Bacarisse said:
    [color=blue]
    > spinoza1111 <spinoza1111@yahoo.com> writes:
    >[/color]
    <snip>[color=blue][color=green]
    >> printf("Swapping %d bytes at %d and %d\n",
    >> intLength, ptrToA, ptrToB);[/color]
    >
    > %o is the format for printing pointers.[/color]

    No, it's %p - and %p is only defined for void *. Whether it will also work
    for char * (because of guarantees about representation and alignment) has
    been a matter of debate, but the safest course is to supply a conversion.

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999

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

    spinoza1111 <spinoza1111@yahoo.com> writes:
    [color=blue]
    > On Feb 16, 10:00 pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:[color=green]
    >> Richard Heathfield <r...@see.sig.invalid> writes:[color=darkred]
    >> > Ben Bacarisse said:[/color]
    >>[color=darkred]
    >> >>spinoza1111<spinoza1...@yahoo.com> writes:[/color]
    >>[color=darkred]
    >> > <snip>[/color]
    >>[color=darkred]
    >> >>> <snip> he has made a significant error in
    >> >>> recommending memcpy without remembering, as the C expert here, that it
    >> >>> is undefined for overlap.[/color]
    >>[color=darkred]
    >> >> Did he?[/color]
    >>[color=darkred]
    >> > No. <snip>[/color]
    >>
    >> Of course not.  I obviously failed to indicate the sarcastic tone of
    >> the question.  Next time I will try "Right, and I am Marie of
    >> Romania"[1].[/color]
    >
    > He did, Ben. He replied to Malcolm's claim that C cannot do a
    > multibyte memory swap with code that used memcpy() and he did not
    > disclose this limitation at the time. When he remembered or perhaps
    > learned the behavior a week later, he told Randy Howard that this was
    > so, and then he proceeded to collude with Howard in a cover up.[/color]

    This is getting silly. I know exactly what has been posted (I have
    read all of these threads). My incredulity related to two things:
    that he made "a serious error" and that he did so "without
    remembering" what memcpy does. If you think the subsequent exchanges
    about overlapping swaps suggest that he'd forgotten anything about
    memcpy, I doubt I can persuade you otherwise, but I did not read it
    that way. If you think the initial dismissal of overlap was a serious
    error, then so be it. I don't see it that way -- I think it is a
    non-issue and leaving it undefined is entirely satisfactory to me.

    --
    Ben.

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


    "Randy Howard" <randyhoward@FOOverizonBAR.net> wrote in message[color=blue]
    > You will kindly point out how the original questioner specified your
    > convention for an implementation of memswap(), and how Richard and
    > others were in error by failing to meet this requirement.
    >[/color]
    I made a combsort(), using the same prototype as qsort(), and comented that
    C doesn't have facilities for swapping except byte-by-byte.

    That's not entirely true, as Heathfield pointed out, because a swap can be
    built on top of memcpy(). However it is not entirely false either, because
    we are supposing that memcpy() itself isn't written in portable C.

    To be fair to Nilges, he did point out that memory accesses could be
    minimised by comparing bytes for equality before writing. My function did
    show a very tiny speedup when swapped variables were pointer-sized, or 4
    bytes of typcial current architectures, in some tests, but in my own the
    memcpy() version was actually faster, though it made only a tiny difference
    to the runtime of the whole sort function.

    --
    Free games and programming goodies.
    [url]http://www.personal.leeds.ac.uk/~bgy1mm[/url]


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

    spinoza1111 <spinoza1111@yahoo.com> writes:
    <snip>[color=blue]
    > I make errors in detail, to be sure.[/color]

    Why are all your errors ones of detail but everyone else's are
    serious? At least serious enough for you to keep going on about them?
    [color=blue]
    > I am less practised at C than Ben
    > who is by far the best programmer here (and whom you haven't had the
    > decency or grace to recognize as such),[/color]

    I would be shocked if anyone did so. I can't see why you say that
    either. There is no evidence that I am "the best programmer here" and
    there is much evidence (on the net) that I am not. I won't embarrass
    anyone by naming names.

    But I am embarrassed that you make such claims. It does not help
    toknow who id good and who is bad. Good programmers can have bad
    ideas and bad programmers can have excellent ones. Let's try to
    discuss posted ideas and not compare people.

    --
    Ben.

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

    On Feb 17, 2:45 am, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:[color=blue]
    > spinoza1111 <spinoza1...@yahoo.com> writes:[color=green]
    > > On Feb 16, 3:08 am, "Bartc" <b...@freeuk.com> wrote:[/color]
    >
    > [I don't know what has happened to your attribution lines, but you are
    > replying to BartC without, it would seem, quoting anything he wrote.
    > Normally I'd snip the above line because I'm not quoting any of it,
    > but since I'm commenting on its inclusion, I think I have to leave it.]
    >
    > <snip>
    >[color=green]
    > > "Overlap swapping" may not be sensible but it's deterministic and
    > > reversible in the sense of undoable because deterministic: it might be
    > > useful in encoding.[/color]
    >[color=green]
    > > The problem: "overlap swapping" is NOT reversible like this[/color]
    >[color=green]
    > > swap(swap(blockA, blockB)) == blockA,blockB[/color]
    >[color=green]
    > > It would seem to me that a memory swap should share this property with
    > > swap of bytes where swap(swap(byte1, byte2)) = byte1,bytes[/color]
    >[color=green]
    > > Fortunately, if you do not swap overlapping bytes then the swap is
    > > reversible.[/color]
    >
    > If you think that useful, go for it.  I can't see the purpose.
    >[color=green]
    > > I believe the following code handles possible overlap.[/color]
    >
    > Nope.  Why don't you post in C#?  What purpose does trying to write C
    > serve?  Most people here can read a wide range of languages and your
    > examples would be clear enough to most.  Some of the errors seem to be
    > logical, but using a language you know will surely reduce the number.
    > Can C# do overlapping memory swaps?[/color]

    No it cannot.

    When in Rome...actually, I enjoy getting back up to speed in C. It's a
    challenge. Thanks for your criticism.

    I program in C with amateur status, and make and fix errors
    repeatedly, in order to "deconstruct" a completely false image of
    programming masculinity which is used here by Heathfield and Howard to
    manipulate and control. You see, I don't "buy" their implicit claim,
    that there are "real" programmers who program close to the metal,
    versus inferior script kiddies and girliemen. I don't buy it, Ben,
    because I established chops far earlier than they by debugging a
    compiler in machine language, and matured rapidly out of what I have
    come to believe is not a truly scientific endeavor, but a form of
    social control.

    Since I've been there and done that in a range of languages that
    included C in the early 1990s, I find it very ugly when Heathfield/
    Howard throw their weight around, since they seem in fact to know very
    little about computer science, object-oriented coding, or other topics
    outside of C, and I think this is why Heathfield constantly snipes at
    better men than he: a profound personal insecurity.

    Therefore I thought it would be amusing to ramp quickly back up to C
    by making online mistakes and using you as a resource, and demonstrate
    the shallowness of an "expertise" which is (in many cases I've seen)
    quietly and without fanfare acquired by "nonprofessional" programmers,
    especially, in my experience, doctors and lawyers with far more
    culture, self-discipline and collegial amiability than are displayed
    by the "professional" programmer, who so often deludes himself that he
    is other than a corporate slave raised for food.

    When I see the insecurity and nastiness here including not only that
    directed at me but also at Schildt, I thank my lucky stars that I am
    no longer in the computer business. At the same time, as I get older,
    I persist in learning and here relearning, time permitting, for the
    same reason I run or work out the equivalent of 20 miles a week.



    As to C sharp. There's no such thing as a von Neumann addressible
    contiguous memory in C sharp, therefore no such thing as "moving
    blocks" at all. However, you can simulate the problem.
    [color=blue]
    >
    >
    >
    >
    >[color=green]
    > > Once it hits a
    > > point where block A byte x is inside block B, it hops to the end of
    > > block B. Let's see, you don't need the opposite test (block B byte y
    > > is inside block A), I think, because for any given byte, it "overlaps"
    > > the corresponding byte iff the corresponding byte overlaps it.[/color]
    >[color=green]
    > > You don't need a byte by byte precheck, or even my assert, this code
    > > handles the checking as part of its main work. The listing is followed
    > > by a preliminary test result. The test is instrumented so you can
    > > watch the swap step by step. It swaps and then it unswaps. The results
    > > and the code are best viewed in a monospace font.[/color]
    >[color=green]
    > > void spinoza1111_memswap(char *ptrToA,
    > >                          char *ptrToB,
    > >                                             int intLength)
    > > {
    > > printf("Swapping %d bytes at %d and %d\n",
    > >        intLength, ptrToA, ptrToB);[/color]
    >
    > %o is the format for printing pointers.[/color]

    So? Why am I permitted to use %d? Either the language enforces it, or
    it's not a rule.[color=blue]
    >[color=green]
    > > if (ptrToA + intLength > ptrToB
    > >     ||
    > >     ptrToB + intLength > ptrToA)
    > >    printf("Overlap swap\n");[/color]
    >
    > This logic is plain wrong.  If we accept the restriction you are
    > implicitly putting on this function (that it can swap only parts of
    > the same object) the code above becomes legal C but is not a check for
    > overlap (the condition is true unless the two pointers are the same --
    > i.e. it is false only for total overlap).[/color]

    Sorry, this code was info only and was left in. But it has a typo
    which I didn't catch, because the only purpose of the code was to
    print "overlap swap": the second greater than sign should have been a
    less than sign.

    I think you're a great coder, but rather inarticulate. Had I spotted
    the error, I would have said "didn't you want that to be a greater
    than sign?", not "this logic is plain wrong", because I would have
    reflected upon and internalized INTENT, something you need to do when
    you read code.
    [color=blue]
    >
    >
    >
    >
    >[color=green]
    > > char chrExchange;
    > > char *ptrToAend = ptrToA + intLength;
    > > char *ptrToAwork = ptrToA;
    > > char *ptrToBwork = ptrToB;
    > > char *ptrToAstart;
    > > char *ptrToBstart;
    > > char *ptrToBblockLimit = ptrToB + intLength;
    > > int intBlockLength;
    > > printBlocks(ptrToA, ptrToB, intLength);
    > > while (1)
    > > {
    > >    do
    > >            {
    > >                    if (ptrToAwork >= ptrToB && ptrToAwork < ptrToBblockLimit)
    > >                            ptrToAwork += ptrToBblockLimit - ptrToB;
    > >                    if (ptrToAwork >= ptrToAend) return;
    > >                    if (*ptrToAwork != *ptrToBwork)break;
    > >                    ptrToAwork++; ptrToBwork++;
    > >            }
    > >    while (1);
    > >    chrExchange = *ptrToAwork;
    > >    *ptrToAwork = *ptrToBwork;
    > >    *ptrToBwork = chrExchange;
    > >    printBlocks(ptrToA, ptrToB, intLength);
    > >    ptrToAwork++; ptrToBwork++;
    > > }
    > > }[/color]
    >
    > And this code does not do what you claim.  Your solution to overlap
    > was not to swap overlapping areas, but unless you also have an odd
    > definition of these, this code does swap the overlapping area (though
    > not all of it and not always).
    >
    > For example:
    >
    >   char t[] = "abcdefgh";
    >   spinoza1111_memswap(t, t + 2, 6);
    >
    > will leave t containing "cdabefgh".  The overlap, is "cdef" in my
    > book, so I'd expect "ghcdefgab" from your definition above.
    >
    > There are two other problems.  The code does not do the same thing
    > when the pointers are reversed.  Surely swap(a, b, n) should have the
    > same effect as swap(b, a, n)?  In the example above
    >
    >   spinoza1111_memswap(t + 2, t, 6);
    >
    > is a no-op.
    >[/color]
    Thanks as always. I will investigate and if possible fix these errors
    if that is what they are. Meanwhile, you might try to express why the
    code doesn't work not merely THAT it fails, unless you don't want to.
    [color=blue]
    > The other is the C issue.  Pointer comparison is only defined for
    > pointer into (and just one past the end) the same object.  In trying
    > to make it more general (do something with overlap) you have made it
    > more restricted.  You can't, for example, swap the contents of two
    > separate arrays.
    >
    > --
    > Ben.- Hide quoted text -
    >
    > - Show quoted text -- Hide quoted text -
    >
    > - Show quoted text -[/color]


+ Reply to Thread
Page 20 of 28 FirstFirst ... 10 18 19 20 21 22 ... LastLast