You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
849 B

/**
* :author: Dan Buch (daniel.buch@gmail.com)
*/
#include <stdio.h>
void duff(register char *to, register char *from, register int count)
{
register int n = (count + 7) / 8;
switch (count % 8) {
case 0: do { *to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
case 2: *to++ = *from++;
case 1: *to++ = *from++;
} while (--n > 0);
}
}
int main()
{
char * to = "dogs cats babies";
char * from = "monkey hat pants";
int i = 16;
printf("to = %s\n", to);
printf("from = %s\n", from);
/* And here comes the segfault... */
duff(to, from, i);
printf("to = %s\n", to);
printf("from = %s\n", from);
}
/* vim:filetype=c:fileencoding=utf-8
*/