[fpc-pascal] string to widestring : what are the difficulties ?

Jonas Maebe jonas.maebe at elis.ugent.be
Sun Oct 9 11:33:21 CEST 2016

On 09/10/16 08:50, Sven Barth wrote:
> Am 08.10.2016 22:48 schrieb "Ched"
> <charles.edouard.des.vastes.vignes at gmail.com
> <mailto:charles.edouard.des.vastes.vignes at gmail.com>>:
>> In http://www.freepascal.org/docs-html/ref/refsu14.html#x37-400003.2.8
>> , the stack sized used by a Shortstring is Declared length + 2 . Why not
>> Declared length + 1 ?
> 1 Byte length and a zero byte to allow easy conversion to PChar.

That is incorrect. Shortstring stringconstants are stored like that in 
the constant data section so they can be used both for assigning to 
shortstrings and to pchars, but shortstring variables/fields themselves 
are never null-terminated by the compiler/RTL.

So there is in fact an error in the documentation: it should be length + 1.


More information about the fpc-pascal mailing list