Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Thu, 01 Sep 2011 18:24:24 -0500 |
| Message-ID | <4E60142A.575D@mindspring.com> (permalink) |
| Date | Thu, 01 Sep 2011 19:24:26 -0400 |
| From | pete <pfiland@mindspring.com> |
| Reply-To | pfiland@mindspring.com |
| Organization | PF |
| X-Mailer | Mozilla 3.04Gold (WinNT; I) |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.c |
| Subject | My latest magnum opus! |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| Lines | 110 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 4.154.223.242 |
| X-Trace | sv3-TPh+uXqx//DK0OpEbks6VegGeX9XAxqU6+nScv6uanRVQKtmzkAa1yyI9ukPcw67AemmfvRslnl3aB4!t45eOPN9kZlhOZqBlxoGxyZlB88davRxQAw1dFBbMKM7jGrzWR7VQmLBLHP0vYU1ZrG1HuuDIx+n!9JVNMAwkFoM= |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 3158 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c:9845 |
Show key headers only | View raw
/* BEGIN block_swap_test.c */
/*
** block_swap swaps two contiguous subobjects.
** (base) is the address of the lower addressed subobject.
** (lo_size) is the size of the lower addressed subobject.
** (hi_size) is the size of the higher addressed subobject.
** If either (lo_size) or (hi_size) or both
** compare equal to zero, then no swapping takes place.
*/
#include <stdio.h>
#define STRING "0123456789A"
void block_swap(void *base, size_t lo_size, size_t hi_size);
int
main(void)
{
char string[] = STRING;
size_t right = sizeof string;
size_t left = 0;
puts("/* BEGIN block_swap_test.c output */\n");
do {
--right;
block_swap(string, left, right);
puts(string);
block_swap(string, right, left);
puts(string);
putchar('\n');
} while (++left != sizeof string);
puts("/* END block_swap_test.c output */");
return 0;
}
void
block_swap(void *base, size_t lo_size, size_t hi_size)
{
size_t mod;
unsigned char *end, *middle, swap;
mod = lo_size != 0 && hi_size != 0;
while (mod != 0) {
end = base;
middle = end + lo_size;
if (hi_size > lo_size) {
mod = hi_size % lo_size;
base = end + hi_size - mod;
do {
swap = *end;
*end++ = *middle;
*middle++ = swap;
} while (--hi_size != mod);
} else {
mod = lo_size % hi_size;
end = middle + hi_size;
do {
swap = *--middle;
*middle = *--end;
*end = swap;
} while (--lo_size != mod);
}
}
}
/* END block_swap_test.c */
/* BEGIN block_swap_test.c output */
0123456789A
0123456789A
123456789A0
0123456789A
23456789A01
0123456789A
3456789A012
0123456789A
456789A0123
0123456789A
56789A01234
0123456789A
6789A012345
0123456789A
789A0123456
0123456789A
89A01234567
0123456789A
9A012345678
0123456789A
A0123456789
0123456789A
0123456789A
0123456789A
/* END block_swap_test.c output */
--
pete
Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread
My latest magnum opus! pete <pfiland@mindspring.com> - 2011-09-01 19:24 -0400
Re: My latest magnum opus! Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-01 21:13 -0400
Re: My latest magnum opus! pete <pfiland@mindspring.com> - 2011-09-01 22:29 -0400
Re: My latest magnum opus! pete <pfiland@mindspring.com> - 2011-09-01 22:58 -0400
Re: My latest magnum opus! pete <pfiland@mindspring.com> - 2011-09-02 00:41 -0400
Re: My latest magnum opus! pete <pfiland@mindspring.com> - 2011-09-02 00:53 -0400
Re: My latest magnum opus! cri@tiac.net (Richard Harter) - 2011-09-02 05:39 +0000
Re: My latest magnum opus! pete <pfiland@mindspring.com> - 2011-09-02 02:59 -0400
Re: My latest magnum opus! Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-02 08:21 -0400
Re: My latest magnum opus! cri@tiac.net (Richard Harter) - 2011-09-02 13:39 +0000
Re: My latest magnum opus! Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-02 20:53 -0400
Re: My latest magnum opus! James Dow Allen <jdallen2000@yahoo.com> - 2011-09-03 03:18 -0700
Re: My latest magnum opus! cri@tiac.net (Richard Harter) - 2011-09-03 17:16 +0000
Re: My latest magnum opus! Andrey Tarasevich <andreytarasevich@hotmail.com> - 2011-09-02 09:21 -0700
Re: My latest magnum opus! ImpalerCore <jadill33@gmail.com> - 2011-09-06 06:51 -0700
Re: My latest magnum opus! pete <pfiland@mindspring.com> - 2011-09-06 18:36 -0400
Re: My latest magnum opus! Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-06 21:04 -0400
csiph-web