Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!gatech!rutgers!cbmvax!daveh From: daveh@cbmvax.UUCP (Dave Haynie) Newsgroups: comp.sys.amiga.tech Subject: Re: M2/C discussion (Re: Can you nest subroutines in C?) Message-ID: <7224@cbmvax.UUCP> Date: 6 Jul 89 17:27:26 GMT References: <8673@pyr.gatech.EDU> Organization: Commodore Technology, West Chester, PA Lines: 39 in article <8673@pyr.gatech.EDU>, dsking@pyr.gatech.EDU ( David King) says: > This brings up something I've been wondering - what are things like *jmp > useful for in an Amiga program? Here's what I use 'em for: #include < jmp_buf lomem; void *salloc(unsigned long amount) { void *mem; if (mem = AllocMem(amount,0L)) return mem; longjmp(lomem,1); } main() { /* ... */ if (setjmp(lomem)) cleanup("Error: Out of memory"); /* ... */ } With that code, I know that the salloc() routine will always succeed. Thus, I never need to check for the success of a memory allocation. If you're doing lots of allocation, this'll save you lots of writing and ugliness all throughout your code, as well as the crash that results the one time you forgot to check to see if AllocMem() really succeeded. I really miss this capability in M2 and C++... > David King - FROM Disclaimers IMPORT Standard; -- Dave Haynie Commodore-Amiga (Systems Engineering) "The Crew That Never Rests" {uunet|pyramid|rutgers}!cbmvax!daveh PLINK: D-DAVE H BIX: hazy Be careful what you wish for -- you just might get it