Re: how to optimize a for loop



On Oct 30, 9:53 pm, Eric Sosman <esos...@xxxxxxxxxxxxxxxxxxxx> wrote:
andreyvul wrote:
I have this loop (all variables are pointers):
for (foo = bar; foo > baz; foo--)
*(foo+1) = *foo;
How do I optimize the pointer swap so that it uses -- and ++ or unary
+- instead of +1 (if possible - I don't want to have more #defines
than code)?
IOCCC winners can really help me with this :P

Assuming the pointers are of the same type:

memmove (baz + 2, baz + 1, (bar - (baz + 1)) * sizeof *baz);

--
Eric Sosman
esos...@xxxxxxxxxxxxxxxxxxxx
sort still fails
actual output: 1 1 3 1 1 1 1 3 1 1
intended output: 1 2 3 4 5 6 7 8 9 10
somehow memmove fails while iterated swap works. wierd.

.



Relevant Pages

  • Re: Problem with Linux Machines Request for ... (8ms!!) -- EOT
    ... And he never listens to anyone. ... some sort of perverse pleasure out of riling up people who try to help him. ... >> snowbat's very interesting discovery, and, if that fails, I will ... >> this discussion narrows down to snowbat and myself, ...
    (comp.os.linux.networking)
  • Re: Doctors may be hazardous to your (mental) health
    ... It is mind boggling that some of us can do most anything and live long with little or no medial problems then others even ones that go above and beyond the rules have medical issues. ... When all else fails go with the professionals I always say. ... The folk that do that sort of thing are similar to those of us who put a new belt on a treadle after spending weeks freeing it from rust and polishing the pitman rod... ...
    (alt.sewing)
  • Re: Smell the desperation :-)
    ... And you were obviously taught maths by some sort of innumerate fuckwit as well. ... 27 miles = 4.546 litres ... And remember kids, RAID is safe and the UPS never fails, and Cisco routers never develop intermittent faults, and external hard drives never fail with only a month's use. ...
    (uk.rec.cars.modifications)
  • Re: How to sort a list of strings on a substring
    ... No, that's incorrect. ... Try it with this data and you will see it fails: ... *not* how to sort the list according to the first character '1'. ...
    (comp.lang.python)
  • Re: templates
    ... You might offer some information on what sort of trouble. ... The credit belongs to the man in the arena, ... achievement, and who at the worst, if he fails, at least fails while ...
    (microsoft.public.word.numbering)