help-bison
[Top][All Lists]
Advanced

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

Re: Wrong value on a type


From: Akim Demaille
Subject: Re: Wrong value on a type
Date: 23 Jan 2001 15:55:44 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.1 (Crater Lake)

Please, don't drop Cc's to lists.

| On 19 Jan 2001, Akim Demaille wrote:
| thanks a lot. That esactly was the problem. All that i did was change 
|  /my_pattern/    { yylval = yytext; return STRING; }
| 
| by the line
|  
|  /my_pattern/    { yylval = strdup (yytext); return STRING; }
| 
| and the problem desapear!. But why do you say that this is not as perfect
| as they could?

Nope, for reasons similar to those given by Hans.  I agree with him I
don't remember having seen a written rule somewhere stating that
yytext is null-terminated, but I never observed the converse.  If you
carefully read the Flex documentation, there are many samples that
would break if the yytext was not 0-terminated (yet it shows how to
use strdup), but I couldn't find any indication about it.

I personally try to avoid relying on this, but it might be
superstition.  In addition I gave myself the rule to consider `\0' is
a valid character (even where the pattern makes it impossible), and
therefore use malloc + memcpy.

But that's overkill, I agree.  Using strdup is fine, strndup if you
don't trust the 0-termination of yytext.




reply via email to

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