支持其他语言达夫设备的工作? [英] Does Duff's Device work in other languages?

查看:83
本文介绍了支持其他语言达夫设备的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多年前,而在紧张的工作图形I / O问题,汤姆·达夫展开的循环,并创造了他的达夫设备如下:

Many years ago while working on a tight graphics I/O problem, Tom Duff unrolled a loop and created his Duff's Device as follows:

dsend(to, from, count)
char *to, *from;
int count;
{
    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);
    }
}

(注意这里使用旧式函数参数 - 这不是一个错误。)

(Note this uses old style function parameters - that's not an error.)

此编码来直接出的汇编思维和用C编码的,并且依赖于C'S case语句落空。可这种创造性的交错控制结构中的任何其他语言的工作?

This coding comes directly out of thinking in assembler and coding in C and is dependent on C's case statement fall-through. Can this kind of creativity in interlacing control structures work in any other languages?

推荐答案

您可以做到在支持计算GOTO语句任何语言(Fortran中,一些基本的,等等。)

You can do it in any language that supports computed GOTO statements (Fortran, some BASICs, etc.)

这篇关于支持其他语言达夫设备的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆