This is the mail archive of the gcc-help@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]

__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


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