Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site drivax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!amdcad!amdahl!drivax!holloway From: holloway@drivax.UUCP (Bruce Holloway) Newsgroups: net.lang.c Subject: Re: a basic like gosub in C Message-ID: <300@drivax.UUCP> Date: Wed, 26-Feb-86 13:05:32 EST Article-I.D.: drivax.300 Posted: Wed Feb 26 13:05:32 1986 Date-Received: Fri, 28-Feb-86 21:55:11 EST References: <202@crunch.uucp> Reply-To: holloway@drivax.UUCP (Bruce Holloway) Organization: Digital Research, Monterey, CA Lines: 43 In article <202@crunch.uucp> josh@crunch.uucp (Josh Siegel) writes: >In basic there is a GOSUB routine that will push the current > position onto the stack and jump to another line. Then, upon > hitting a return will return to that place. I wish to write > something like that in C that will be movable between compilers. (Sorry I'm not sending MAIL... but it doesn't seem to work from "rn" under the C shell....) You should use the setjmp() and longjmp() routines. Call setjmp with a implementation specific environment buffer. When a longjmp is called with the same buffer, it returns from the setjmp with a return code. setjmp returns zero in a normal routine, or the longjmp parameter if that's wwhere it came from. Hmmm. jmp_buf env; func(){ : : if(setjmp(env)){ /* Code executed when returning from LONGJMP */ } : : longjmp(env,ret_code); } -- +----------------------------------------------------------------------------+ |Whatever I write are not the opinions or policies of Digital Research, Inc.,| |and probably won't be in the foreseeable future. | +----------------------------------------------------------------------------+ Bruce Holloway ....!ucbvax!hplabs!amdahl!drivax!holloway (I'm not THAT Bruce Holloway, I'm the other one.)