Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!caip!seismo!umcp-cs!jim From: jim@umcp-cs.UUCP (Jim Williams) Newsgroups: net.lang.c Subject: A good use of a bad feature Message-ID: <1298@umcp-cs.UUCP> Date: Sat, 3-May-86 00:26:28 EDT Article-I.D.: umcp-cs.1298 Posted: Sat May 3 00:26:28 1986 Date-Received: Tue, 6-May-86 03:37:59 EDT Organization: Computer Sci. Dept, U of Maryland, College Park, MD Lines: 90 Keywords: case statement, tacky programs While discussing various features and miss-features of C with my friend Charley (mangoe) Wingate recently, we both agreed that the fall through case statement is among the least defensible of C's features. I submit the program below as the best use I have ever found for this feature. --------------- CUT HERE ------------ /* * xmas.c - a program to print The Twelve Days of Christmas * using the C fall thru case statement. * If this wasn't my idea, I appologize to whomever I * got the idea from, but I wrote the program 5 years * ago and I don't remember now. * * Jim Williams, jim@maryland, 2 May 1986 */ /* * If you have an ANSI compatible terminal then * #define ANSITTY. It makes the five Golden rings * especially tacky. */ #define ANSITTY #include char *day_name[] = { "", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" }; main() { int day; printf("The Twelve Days of Christmas.\n\n"); for (day=1; day<=12; day++) { printf("On the %s day of Christmas, my true love gave to me\n", day_name[day]); switch (day) { case 12: printf("\tTwelve drummers drumming,\n"); case 11: printf("\tEleven lords a leaping,\n"); case 10: printf("\tTen ladies dancing,\n"); case 9: printf("\tNine pipers piping,\n"); case 8: printf("\tEight maids a milking,\n"); case 7: printf("\tSeven swans a swimming,\n"); case 6: printf("\tSix geese a laying,\n"); case 5: #ifdef ANSITTY printf("\tFive [1;5;7mGolden[0m rings,\n"); #else printf("\tFive Golden rings,\n"); #endif case 4: printf("\tFour calling birds,\n"); case 3: printf("\tThree French hens,\n"); case 2: printf("\tTwo turtle doves, and\n"); case 1: printf("\tA partridge in a pear tree.\n\n"); } } } -- Jim \/\/illiams jim@mimsy.umd.edu umcp-cs!jim.UUCP