[antlr-interest] Stack overflow problem with C++

Jorg Halker jogi1978 at gmx.de
Tue Jul 19 09:14:37 PDT 2005


Hi!

Okay, i tried it with linux (feodora core 2) and gcc (v3.2.2). It looks like
that the stack is larger there. So if i count until 150000 i have the same
problem with linux and gcc: segmentation fault/stack overflow. But if i set
up a parser which parses a file and creates an ast with the same amount of
ast nodes like the loop from the code snippet does, everything is fine and
the program exits well.

Is it intended that the loop creates objects on the stack?? am i wrong if i
think that the stack should not overflow because the objects should be
created on the heap?? 

Thank you!

Joerg

> -----Original Message-----
> From: Ric Klaren [mailto:ric.klaren at gmail.com] 
> Sent: Tuesday, July 19, 2005 9:24 AM
> To: Jorg Halker
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Stack overflow problem with C++
> 
> On 7/19/05, Jorg Halker <jogi1978 at gmx.de> wrote:
> > If i run the following code i get a stack overflow error:
> > 
> > ****************************************
> > #include <antlr/CommonAST.hpp>
> > 
> > using namespace antlr;
> > using namespace std;
> > 
> > int main(int argc, char * * argv)
> > {
> >         RefCommonAST first = RefCommonAST( new CommonAST());
> >         RefCommonAST current = first;
> >         for (unsigned int counter = 0; counter < 9000; ++counter)
> >         {
> >                 current->setNextSibling(RefAST( new CommonAST()));
> >                 current = current->getNextSibling();
> >         }
> > }
> > ****************************************
> > 
> > It looks like a problem with the destructor of CommonAST or 
> its base 
> > classes. The error occours if 'first' runs out of the scope.
> > If i create a parser that parses an input file into the same AST 
> > scheme, everything works fine. But if i create a copy of 
> the AST from 
> > the parser i run into the same problem.
> > 
> > What's wrong? The code snippet should not produce an stack overflow 
> > error, am i right?
> 
> Nope it shouldn't (and it doesn't on a number of machines I have acces
> to) Which leads to the question:  What antlr version? What 
> OS? What compiler?
> 
> Cheers,
> 
> Ric
> 



More information about the antlr-interest mailing list