This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
__attribute__ ((malloc)) semantics?
- From: Martin Dickopp <firefly-mail at gmx dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 10 May 2003 01:47:59 +0200
- Subject: __attribute__ ((malloc)) semantics?
Hi,
I'm a bit confused what the effect of __attribute__ ((malloc)) is.
The GCC manual says:
The `malloc' attribute is used to tell the compiler that a function
may be treated as if it were the malloc function. The compiler
assumes that calls to malloc result in a pointers that cannot
alias anything. This will often improve optimization.
What does is mean to treat a function as if it were the malloc function,
other than assuming that the returned pointer does not alias anything?
E.g., would it be safe to use __attribute__ ((malloc)) on the following
function?
int *foo (void) { static int i; return &i; }
Thanks,
Martin