[fpc-devel] WideString vs UnicodeString / len in char vs byte / *nix vs windows

Martin fpc at mfriebe.de
Thu Apr 25 15:41:53 CEST 2019

Looking at https://bugs.freepascal.org/view.php?id=35359
and the latest comments (see end of mail)

Is it correct, that "widestring" here has 2 meanings?
- the "widestring" that has length in bytes (windows bstr)
- "widestring" as a typename / alias

And apparently then on *nix, "widestring" is just an alias (to 
So using the type with the name of "widestring" on *nix will compile to 
a type that has length in chars?

At least my test app, seems to imply this.

> Is the len on widestring always in bytes?
> This prints the dwords in front of each string.
> On Windows, it indeed prints 10 for a widestring of len 5.
> But on linux, it prints 5 for all the strings.
> Tested 64 bit.
^^ test source with wide and uni string of len 5, and memory dump of 
string header
> Anyway the patch seems to work for linux too (only tested 64 bit)
> widestring seems to be an alias for unicodestring in this case. 
Serge Anvarov:
> Yes, the length field for WideString is specified in bytes.
> For compatible with Delphi 
> (http://docwiki.embarcadero.com/RADStudio/Rio/en/Internal_Data_Formats_%28Delphi%29#Wide_String_Types) 
> and Windows BSTR type 
> (https://msdn.microsoft.com/en-us/windows/desktop/1B2D7D2C-47AF-4389-A6B6-B01B7E915228) 

More information about the fpc-devel mailing list