Help with Duff's Device in C++

Hi, I am working on this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
 
send(to, from, count)
{
         register int *to, *from;
         register int count;
         {
                 register 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()
{
	int i;
	int a[5]={1,2,3,4,5};
	int b[]={0,0,0,0,0};
 
	/*output each a[i] and b[i] in decimal separated by a Tab on one line*/
	for(i=0; i<5; i++)
		printf("%d\t%d\n", a[i], b[i]);
 
	printf("----------------\n");
 
	send(b, a, 5);
 
	for(i=0; i<5; i++)
		printf("%d\t%d\n", a[i], b[i]);
}

and am getting the following error:

1
2
expected constructor, destructor, or type conversion before '(' token
I've tried using different types but it only gives me more errors. Can anyone help me fix this? 
WTF? Is this a joke?
Last edited on
What are you trying to do by using the pointer to increament ?
send(to, from, count)

Is this a function header? It should have a return type (void if nothing is to be returned).

EDIT: Furthermore, the parameters should have types, as well (int, char, bool, etc).
Last edited on
It's not a joke: http://en.wikipedia.org/wiki/Duff%27s_device

Todays C just looks different (if that makes sense nowadays is another question)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
send(register int *to, register int *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);
                 }
         }
}
Thanks for clarification. Never heard of it before.
Last edited on
Topic archived. No new replies allowed.