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]

Re: __attribute__ ((malloc)) semantics?


On Sun, May 11, 2003 at 02:58:40PM +0200, Martin Dickopp wrote:
> 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.

I suspect if you can guarantee that all references to the previous pointer are
now dead (as far as the compiler is concerned), it will work.  The problem is
as optimization technology improves things that used to work in one revision
may not work in a future revision.

-- 
Michael Meissner
email: meissner@the-meissners.org
http://www.the-meissners.org


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