Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Resource acquisition is initialization
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-12-13 (17:05)
From: David Brown <caml-list@d...>
Subject: Re: [Caml-list] Resource acquisition is initialization
On Fri, Dec 13, 2002 at 12:22:16PM +0300, Mike Potanin wrote:

> > char * foo(...) {
> >     char buf[];
> >     /* do something to fill buf */
> >     return buf;
> > }
> >
> > This sounds like a wonderful way to introduce dangling pointer bugs in the
> > language.

> Cyclone language handle this problec staticaly (compile time). It no need
> GC use.

Numerous languages handle this kind of construct.  Often, though, you
end up having to copy the result when you return.  However, they
wouldn't handle it if the function was defined to return a pointer.
Instead, however, they let functions return larger objects (such as

Usually they are implemented with a secondary stack to hold these

I suspect, though, that the additional copying that ends up happening
with the technique ends up being as, or more, expensive than Ocaml's
garbage collector, especially if the data doesn't live long and doesn't
survive the young area.

Dave Brown
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: