Re: error handlling in recursive function
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 30 May 2008 15:46:14 GMT
David Resnick <lndresnick@xxxxxxxxx> wrote:
On May 30, 9:22 am, pereges <Brol...@xxxxxxxxx> wrote:
How to to go about this ? Suppose a malloc inside a recursive function
has failed and you want to set the error flag and return it to the
calling function(the one which called the recursive function in the
first place)
Options seem to be:
1) Propagate the flag back through the stack of recursive functions,
checking for it at each invocation. This is the best way if you need
to, say, release resources in each invocation of the recursive
function, which seems possible given that you are mallocing in the
recursion.
2) Use setjmp (before entering recursion) and longjmp to hop back on
error.
A third option might be to have a global variable (at file scope)
that gets set if an error occurs. Ok, global variables are EVIL,
but this may be one of the cases where their use can simplify
things a bit...
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- Follow-Ups:
- Re: error handlling in recursive function
- From: David Resnick
- Re: error handlling in recursive function
- References:
- error handlling in recursive function
- From: pereges
- Re: error handlling in recursive function
- From: David Resnick
- error handlling in recursive function
- Prev by Date: Re: reinitialization an array
- Next by Date: Re: Four or Two Bytes?
- Previous by thread: Re: error handlling in recursive function
- Next by thread: Re: error handlling in recursive function
- Index(es):
Relevant Pages
|