Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site uwvax.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!gatech!seismo!uwvax!Thomas Scott Christiansen From: root@rsch.wisc.edu (Thomas Scott Christiansen) Newsgroups: net.lang.c Subject: Re: mildly obfuscating c Message-ID: <464@uwvax.UUCP> Date: Wed, 11-Dec-85 07:51:38 EST Article-I.D.: uwvax.464 Posted: Wed Dec 11 07:51:38 1985 Date-Received: Sat, 14-Dec-85 00:39:13 EST References: <288@epicen.UUCP> <564@puff.UUCP> Sender: daemon@uwvax.UUCP Distribution: net Organization: U of Wisconsin CS Dept Lines: 60 Thanks to all of you who have mailed me suggestions regarding my C question on computed gotos. No, I have not been doing too much FORTRAN programming. I was actually just curious what various systems would do with that code. Most of you suggested that I use a switch statement. My own solution (which I have actually used) is the jump table code given below. Any routine that really wants to exit will do a "longjump(env,1);" to return from the msgs() function. Forgive me for declaring all of these functions ints; the compiler I was using hated voids with a passion. tom =================================================================== extern int superuser; extern jmp_buf env; extern int show_menu(); msgs() { int (*jump[128])(); static beenhere = 0; load_table(jump); if (setjmp(env) == 0) for (;;) { show_menu(); (*jump [get_opt()])(); } } load_table( j ) int (*j[])(); { register i; extern leave_comment(),enter_message(),file_transfer(),kill_message(), go_back(),newdir(),whos_on(),finger(),get_help(),quick_summary(), reset_time(),do_shell(),delete_comment(), show_comments(), long_summary(),say_time_on(),message_stat(),logout(),do_nothing(), switch_expert(),long_menu(),super_expert(),get_mesg(),toggle_pause(); for (i=0;i < 128; i++) j[i] = do_nothing; j [ 'C' ] = leave_comment; j [ 'E' ] = enter_message; j [ 'F' ] = file_transfer; j [ 'K' ] = kill_message; j [ 'M' ] = go_back; j [ 'G' ] = logout; j [ 'N' ] = newdir; j [ 'O' ] = whos_on; j [ 'P' ] = toggle_pause; j [ 'Q' ] = quick_summary; j [ 'S' ] = long_summary; j [ 'R' ] = get_mesg; j [ 'T' ] = say_time_on; j [ 'U' ] = do_finger; j [ '#' ] = message_stat; j [ 'X' ] = switch_expert; j [ '?' ] = long_menu; j [ 'H' ] = long_menu; if ( superuser ) { /* sysop */ j [ '6' ] = reset_time; j [ '7' ] = do_shell; j [ '8' ] = delete_comment; j [ '9' ] = show_comments; } } ===================================================================