This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: implement __attribute__((cleanup(function)))
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Richard Henderson <rth at twiddle dot net>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: 05 May 2003 21:41:59 -0300
- Subject: Re: implement __attribute__((cleanup(function)))
- Organization: GCC Team, Red Hat
- References: <20030505235727.GA21840@twiddle.net>
On May 5, 2003, Richard Henderson <rth@twiddle.net> wrote:
> +@item cleanup (@var{cleanup_function})
> +@cindex @code{cleanup} attribute
> +The @code{cleanup} attribute runs a function when the variable goes
> +out of scope. This attribute can only be applied to auto function
> +scope variables; it may not be applied to parameters or variables
> +with static storage duration. The function must take one parameter,
> +a pointer to a type compatible with the variable. The return value
> +of the function (if any) is ignored.
> +
> +If @option{-fexceptions} is enabled, then @var{cleanup_function}
> +will be run during the stack unwinding that happens during the
> +processing of the exception. Note that the @code{cleanup} attribute
> +does not allow the exception to be caught, only to perform an action.
> +It is undefined what happens if @var{cleanup_function} does not
> +return normally.
How about:
int i = 0, j = 0;
if(*({
auto void f(int **);
int *pi __attribute__((cleanup(f))) = &i;
void f(int **ppi) { **ppi = 1; pi = &j; }
pi; }))
{
printf ("true\n"):
}
else
{
printf ("false\n");
}
when f() is executed, is pi still in scope? But then, why is f()
executed? What is the expected output of this program?
This extension is obviously not as simple as one might think. I still
think coming up with a new extension is a mistake. I'd much rather go
with try/finally, a well-known extension that is likely to be
standardized, than coming up with a new extension with odd
interactions with other extensions 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