char** to {'':('',)}

Alex Martelli aleax at aleax.it
Wed Sep 5 11:01:30 CEST 2001


"David Bolen" <db3l at fitlinxx.com> wrote in message
news:u66ay3er3.fsf at ctwd0143.fitlinxx.com...
> "Alex Martelli" <aleax at aleax.it> writes:
>
> > That's why try/finally was introduced -- ENSURE "needed cleanup"
> > does get performed no matter how the try-block is exited (this
> > includes return as well as exceptions).
>
> I can get try/finally in C (the samples of code under discussion)?
> (Well, I guess MS has some custom extensions that work, but it's not
> portable)

Yes, NT's "Structured Exception Handling" (SEH) is quite usable,
but not portable to other OS's.

> I agree in languages that support it, that the try/finally construct
> is perfect for this sort of thing.  But absent such support, I'm not a
> big fan of multiple exits from a code path unless really necessary.

If you have neither try/finally, nor other ways to ensure
finalization (e.g., C++'s assurance that destructors of
auto objects execute on block exit), then multiple exit
paths may indeed play havoc with your finalization needs.

That's a valid use for goto in C -- jump to finalization
code, since the language is not expressive enough to
otherwise ensure finalization code is run.  Goofy when
compared to either try/finally or C++'s auto-objects
destructors, of course, but a price to be paid if one
is constrained to use a low-level language.

One small aside -- alloca can often save you from this
need, when your finalization needs are limited to freeing
memory that was dynamically allocated within the current
function.  Yes, alloca IS technically non-portable, but
it works fine with either gcc or MS Visual C++, and that
makes it cross-platform enough for _my_ use...:-).  It's
also pretty nice and fast wrt malloc/free... and if I'm
using C it's likely that I AM trying to squeeze every
machine cycle I can (else why would I be coding C?-)...


Alex






More information about the Python-list mailing list