変わった case 文2007年10月13日 11時48分33秒

Duff's Device。この技法自体はアセンブリ等で一般的なのだが、変わっているのは case 文の使い方。この様に、case を置いても問題ないのは知らなかった。

	send(to, from, count)
	register short *to, *from;
	register 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);
		}
	}

面白い switch の使い方があるよと聞いて教わったのがこれだった。