[fpc-pascal]absolute identifier

ron wilson ron.wilson at coastgames.com
Wed Apr 10 21:09:32 CEST 2002


how about for type casting?

  var 
    buf: array[1..255] of char;
    buflen: byte;
    str: ansistring;
  ...
  str:=ansistring(buf);
  setlength(str,buflen);

should i setlength before typecasting?

thx,
ron wilson 


-----Original Message-----
From: fpc-pascal-admin at deadlock.et.tudelft.nl
[mailto:fpc-pascal-admin at deadlock.et.tudelft.nl]On Behalf Of Jonas Maebe
Sent: Wednesday, April 10, 2002 8:52 AM
To: fpc-pascal at deadlock.et.tudelft.nl
Subject: Re: [fpc-pascal]absolute identifier



On dinsdag, maart 26, 2002, at 04:43 , ron wilson wrote:

> so in my application, yyleng is referencing the length of the string,
> yytext, by using the absolute identifier.  i thought i could change all
> references to yyleng to length(yytext), but the lexer often assigns 
> yyleng
> manually (ugh!), e.g. yyleng:=n; OR inc(yyleng);.

You can use setlength(yytext,n) and setlength(yytext,length(yytext)+1) 
in those cases. But when you're using ansistrings, make sure you do 
those length adaptions *before* you write anything past the previous 
end-of-string, since otherwise you'll get segmentation faults.


Jonas


_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal





More information about the fpc-pascal mailing list