Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

You're tangling a bunch of stuff together in a confusing mess. Let's take one thing at a time.

1. You're right that you can't use the & operator on a variable that was declared using the register keyword.

2. However, if you look very carefully at the example code, it actually follows this rule. In fact, it doesn't use the & operator at all. There's a lot of pointers all over the place, but no usage of the & operator.

3. You're also right that the register keyword is just a hint that the compiler is free to ignore.

4. Expanding on the previous point: modern compilers usually will ignore it, but in the olden days, compilers were not so good at register allocation, so this keyword was needed if you wanted speeds competitive with assembly. Since this is code from the 80s, no surprise that it uses this keyword.

5. Now that we've got all that out of the way: the register keyword is a complete distraction here, and has nothing at all to do Duff's device. Since modern compilers ignore it anyway, you can take the original example and just delete all uses of the word "register". The point of Duff's device is how to do manual loop unrolling without then having a special "pre-loop" or "post-loop" which takes care of "leftovers" because your array size was not divisible by 8, or 4, or whatever unroll factor you happened to use.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: