[antlr-interest] "finally" blocks

Alan Gutierrez alan-antlr-interest at engrm.com
Mon Jan 17 22:26:50 PST 2005

* Paul J. Lucas <pauljlucas at mac.com> [2005-01-18 01:13]:
> On Tue, 18 Jan 2005, Alan Gutierrez wrote:
> > Paul J Lucas wrote:

> > > 	I don't have Bjarne's book in front of me, but he talks about
> > > 	the general concept is about resource aquisition and release
> > > 	(which is mostly what "finally" in Java is used for, e.g., open
> > > 	a file, make sure it's closed, etc.).

> >     RAII. Resource Allocation is Initialization. Modern C++
> >     relies heavily on the use of destructors to restore state
> >     when the stack is unwound.

> 	Yes, I know.

> >     The question as to whether it is general, I'm not sure I
> >     understand. If you're wondering whether it is a generally
> >     accepted practice in C++, the answer is yes.

> 	I wasn't asking.  I think you're misquoting.  Terence was the
> 	one who was asking.

    Yes. I know. And if Terrence was asking if reliance of
    destructors is prevelent in C++, in leiu of finally, I'm saying,
    the answer is yes.

> > > 	In ANTLR for C++, you don't need "finally" at all because if
> > > 	the user wants the functionality, s/he can simply do what I
> > > 	did, i.e., create a variable having a destructor.

> >     And a decent C++ type is built around RAII and a destrcutor that
> >     does the right thing.

> 	Yes, I agree, but there's no such standard type wrappers for
> 	built-in types which is exactly what my example was for.

> 	The lone standard such wrapper is auto_ptr<T>.

    Boost has a number of such wrappers. I also consider the
    std::string, std::list, std::vector to be RAII wappers.

> >     You could still have that finally block for C++ ...
> 	How, exactly?  if I have:

> >     Finally exists in C++ ...

> 	No it doesn't.

    My mistake. I'll go back to saying, for C++, forget about it.

Alan Gutierrez - alan at engrm.com

More information about the antlr-interest mailing list