Re: how to optimize a for loop
- From: Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Oct 2007 21:53:13 -0400
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
esosman@xxxxxxxxxxxxxxxxxxxx
.
- Follow-Ups:
- Re: how to optimize a for loop
- From: andreyvul
- Re: how to optimize a for loop
- References:
- how to optimize a for loop
- From: andreyvul
- how to optimize a for loop
- Prev by Date: Re: Hello, World!
- Next by Date: Re: printf("%d",float)
- Previous by thread: Re: how to optimize a for loop
- Next by thread: Re: how to optimize a for loop
- Index(es):