This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: function attributes on function pointers
- From: Ian Lance Taylor <iant at google dot com>
- To: Tim Blechmann <tim at klingt dot org>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 22 Jun 2011 08:42:44 -0700
- Subject: Re: function attributes on function pointers
- References: <itn355$5t7$1@dough.gmane.org>
Tim Blechmann <tim@klingt.org> writes:
> is there a way to use function attributes on function pointers?
>
> my program uses a function table for a plugin interface, which includes a
> function to allocate memory:
>
> void* (*myAlloc)(Host * myHost, size_t size);
>
> is it possible to use the malloc attribute for this to help the optimizer? i was
> trying something like:
> void* __attribute__ ((malloc))(*myAlloc)(Host * myHost, size_t size);
>
> ... but the attribute will be ignored ...
In general, you can use function attributes on function pointers like
this:
void * (* __attribute__ ((malloc)) my_malloc) (size_t) = malloc;
Unfortunately, this is only supported for some attributes. It will only
work if the attribute can be attached to a function type rather than to
a specific function declaration. The malloc attribute is not
implemented in that way, so this does not work for the malloc attribute.
I don't think it would be very difficult to implement this if you are
interested in trying.
Ian