38 lines
849 B
C
38 lines
849 B
C
/**
|
|
* :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
|
|
*/
|