[fpc-devel] dominant short strings in compiler source

Daniël Mantione daniel.mantione at freepascal.org
Tue May 16 18:49:46 CEST 2006



Op Tue, 16 May 2006, schreef peter green:

> how about adding a "shortstring length error" option and using it when
> compiling the compiler. The compiler must be doing length checking anyway to
> give clean truncation so i can't imagine this would bring a signifiant
> performance penalty.
> 
> This would make bugs related to shortstring overflow much easier to trace!

No, shortstring are completely safe types to use and therefore truncation 
is automatic i.e.:

s[0]=#255;
fillchar(s[1],255,'a');
s:=s+'a';

...will result in a string with 255 a's.

To display an error we would have to add manual checks in a lot of places, 
and strings are often used in inner loops in the compiler. (The compiler 
is very, very string sensitive, it spends an important parts of the 
compile time manipulating strings).

Usually, if a shortstring is not enough, you are trying to squeeze a list 
of something into a string. Convert the data structure into a data type 
suitable for a list, and the problem is solved in most cases. This is 
the case with linker options.

Daniël


More information about the fpc-devel mailing list