This is the mail archive of the gcc-patches@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: implement __attribute__((cleanup(function)))


On May  5, 2003, Richard Henderson <rth@twiddle.net> wrote:

> On Mon, May 05, 2003 at 09:41:59PM -0300, Alexandre Oliva wrote:
>> When f() is executed, is pi still in scope?

> Yes, obviously.  Otherwise we wouldn't be able to 
> reference its memory.

Then the documentation could use some improvement:

> +The @code{cleanup} attribute runs a function when the variable goes
> +out of scope.

make it `when the variable is about to go out of scope'.

>> What is the expected output of this program?

> false.

>> This extension is obviously not as simple as one might think.

> It's exactly equivalent to C++ destructors.

There are important differences.

In C++, for example, the result of the statement expression outlives
the scope, and the destruction of temporaries created in an expression
occurs at the end of the full enclosing statement.

Also, in C++, destructors are never nested functions.

> Likewise I'm sure that contorted corner cases can be found for
> try/finally.

I doubt it.  try/finally is far more well-behaved than
attribute((cleanup)).  We're going the wrong way.

> I refuse to have this discussion.  I've done it twice now in
> favour of try/finally, and now you want to start in on the only
> technically sound replacement that's been proposed since.

I don't think it's technically sound.  I think it's try/finally
rephrased to appease those who dislike syntax extensions, but will go
with a language extension that's more dangerous but just happens to
rely on another extension that we already have.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer


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