__attribute__ ((malloc)) semantics?

Martin Dickopp firefly-mail@gmx.net
Sun May 11 12:58:00 GMT 2003


On Sat, May 10, 2003 at 10:08:39PM -0400, Michael Meissner wrote:
> On Sat, May 10, 2003 at 01:47:59AM +0200, Martin Dickopp wrote:
> > E.g., would it be safe to use __attribute__ ((malloc)) on the following
> > function?
> > 
> >     int *foo (void) { static int i; return &i; }
> 
> No, because repeated calls to foo will return the same pointer, which
> would create aliases.

Let me rephrase my question: Could it be safe to use __attribute__
((malloc)) on the above function in some circumstances?

What if any pointer previously returned by foo is considered to become
invalid every time foo is called? Even repreated calls to malloc (with
intervening calls to free) can return the same address.

Martin



More information about the Gcc-help mailing list