Re: how to optimize a for loop
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Oct 2007 23:11:50 -0400
andreyvul wrote:
On Oct 30, 9:53 pm, Eric Sosman <esos...@xxxxxxxxxxxxxxxxxxxx> wrote:andreyvul wrote:I have this loop (all variables are pointers):Assuming the pointers are of the same type:
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
memmove (baz + 2, baz + 1, (bar - (baz + 1)) * sizeof *baz);
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.
Then something is wrong with your sort, or else I mis-
translated your loop (fencepost error, maybe?), or else the
assumption of identically-typed pointers is wrong. Show
some code -- and I don't mean the out-of-context partial
snippet you posted elsethread; I mean show a short, complete,
compilable program that demonstrates your problem. (I for
one have had it up to HERE with trying to debug paraphrases.)
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.
- References:
- how to optimize a for loop
- From: andreyvul
- Re: how to optimize a for loop
- From: Eric Sosman
- Re: how to optimize a for loop
- From: andreyvul
- how to optimize a for loop
- Prev by Date: Re: Macro that expand differently depending on the function calling it.
- Next by Date: Re: Macro that expand differently depending on the function calling it.
- Previous by thread: Re: how to optimize a for loop
- Next by thread: Re: Hello, World!
- Index(es):