help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory Allocation in Bison


From: Martin Bock
Subject: Memory Allocation in Bison
Date: Tue, 6 Feb 2007 13:12:24 +0100

Hi everybody,


I have have a question concerning memory allocation for yyval in bison:
I' looking for the memory reserved for yyval, how it is done and how
much it is. In the .c-file generated by bison, I found yyval is of the
type YYSTYPE. But I cannot find any information about the memory. Also,
I found no about it in the help archive.


What it is all about:

My parser is working direct on the bison-made variables (all those $$,
$1...). It's like this:
{...
        strcat($1, $2);
        $$ = $1;
...}

Up to now, I had no problems with this. But I'm not sure: is it right to
extend $1 this way, or am I doing some real big-memory-chaos-thing? 

Is it wiser to do it this way:
{...
        char *temp = malloc( (3+strlen($1)) );
        strcat(temp , $2);
        $$ = temp;
...}


In fact I'm just starting with flex and bison, and even with C, so I'm
sorry if this is a stupid question.




Regards and thanks,
Martin Bock


reply via email to

[Prev in Thread] Current Thread [Next in Thread]