[Top][All Lists]

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

Re: Wrong value on a type

From: Hans Aberg
Subject: Re: Wrong value on a type
Date: Fri, 19 Jan 2001 23:27:11 +0100

At 18:07 +0100 1-01-19, Akim Demaille wrote:
>My bet is that it is your scanner which is wrong.  Make sure it uses
>(allocates for instance) a different space for each string.  The
>typical error would be
>/my_pattern/    { yylval = yytext; return STRING; }
>in a Lex scanner, as yytext *belong to Lex* which does whatever it
>wants with it.  Roughly (but still not perfect), write
>/my_pattern/    { yylval = strdup (yytext); return STRING; }

I think that yytext isn't '\0' terminated, one only knows that the
character is yyleng long.

One way is to switch to C++, writing
<pattern>    { yylval = std::string(yytext, yyleng); return STRING; }
where yylval must be of type std::string as well.

  Hans Aberg

reply via email to

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