?

Log in

Previous Entry | Next Entry

Lunch Break

I found the most evil C code that I have ever seen the other day.
	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);
		}
	}

If you cannot figure out its purpose (I couldn't) you can get the full story surrounding it.

Comments

( 5 comments — Leave a comment )
veloso
Aug. 24th, 2001 02:03 pm (UTC)
Damn Djikstra. Because of him, any piece of code that uses gotos in any interesting way is evil.
grieve
Aug. 24th, 2001 08:42 pm (UTC)
No gotos
There are no gotos in this code. It is evil, because it has intertwined two control structures, and if what the author claims is true. It is valid ansi C. But you know that, chain yanker.
veloso
Aug. 24th, 2001 09:31 pm (UTC)
Re: No gotos
No, I mean, come on, what is switch() but a fancy computed goto? This is exactly what he's doing, no? Doing a calculated jump into an unrolled loop. Very goto-y.

No reason to suspect it isn't legal, either. But oh well.
grieve
Aug. 24th, 2001 09:38 pm (UTC)
Re: No gotos
Well sure. The same can be said of all the control structures: if, do while, while, for, break, continue, function calls, function returns! He never actually uses the goto statement. That was my point.
veloso
Aug. 25th, 2001 08:57 am (UTC)
Re: No gotos
Well, sure. But it wouldn't have been as much fun if I was ACCURATE about it, now would it?
( 5 comments — Leave a comment )

Latest Month

July 2011
S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
31      

Page Summary

Powered by LiveJournal.com
Designed by yoksel