This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: __attribute__((cleanup(function)) versus try/finally


On 08 May 2003 13:58:54 +0200, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:

> Jason Merrill <jason@redhat.com> writes:
>
> [...]
>
> | >  o Mark (and others) are against adding try/finally and favor adding
> | >  a different extension: __attribute__((cleanup(function)) which is
> | >  "lighter" in a sense.
> | 
> | I agree with Alex's comments on this approach; it's trying to introduce the
> | C++ object model into C, which seems like rather a backwards way to
> | approach exception cleanliness.
>
> Well, whatever is put in C will (implementation-wise speaking) end up
> in C++.  Therefore if you try to put try/finally in C then you've got to
> think about how it is suposed to work with C++.

Indeed, that's why Aldy's patch added __finally to C++ as well.  We did
think about how it would work.  It works just like it does in Java--there,
that was easy.

Specifically, a try-block can have both catch and __finally clauses; the
__finally must come at the end, and the construct is equivalent to two
separate try blocks, with the try/catch inside the try/__finally.

> And if there is an existing or close to existing mechanism in C++ to
> achieve those effects then I think it makes sense to write out the C++
> approach and try to see which bits can be safely added to C.  There is
> nothing backward in that approach.  Rather, it looks rather smooth.

I'm sympathetic to this approach, but the fundamental difference between C
and C++ (at least originally) is that C is a procedural abstraction
language, and C++ is an object-oriented language.  It makes sense to tie
cleanups to objects in an object-oriented language; it makes sense to write
them explicitly in a procedural language.

> In the past a bunch of extensions have been added to C without thinking
> about how they would intereact with the rest of the langage and the rest
> of C++.  I believe that is clearly a bogus way to extend C.

That's not the case here.  try/finally has already been implemented many
times.  The semantics are well understood.

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]