[fpc-pascal] Warning not to use the "String" type with FPC 3.x

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Mon May 9 11:57:15 CEST 2016


Hi,

I really think the FPC team should make it blatantly clear that the
usage of the aliased "String" type should not be used any more with FPC
3.x.  It turn I think major alarm bells should start ringing when
AnsiString type is used too.

Both are fraught with dangers of loosing data. I've long given up with
the UTF-16 vs UTF-8 debate. FPC has now made an even bigger mess than
Delphi 2009 did. I've now reached the point where I think - just switch
the RTL to UTF-16 only so we can stop loosing data during string
conversions! Java does it, C# does it, Delphi 2009 does it. It's time
FPC stops trying to please everybody, and switch too.

My reasoning for the above. Data loss during string conversions!

1. The "String" type has too many meanings. I recommend you simply stop
   using it in your code. Instead, use the exact type you really mean or
   support in your application.

2. AnsiString in FPC 3.x is now code page enabled, and can have many
   different meanings.
   There is no guarantee that assigning a UTF8String or UnicodeString
   to a AnsiString is safe. On some systems the AnsiString might
   default to a UTF-8 or UTF-16 encoding which is fine, but importantly,
   on other systems in might default to something else, and then you
   simply loose data during the conversion. What makes it even worse,
   is that the default encoding for AnsiString is determined at
   runtime, so the programmer is completely helpless in preventing
   this. This issue is also not specific to only certain operating
   systems. You can have a Linux or FreeBSD system that defaults to
   a non-Unicode type code page, yet the Linux system running right
   next to that one could have been set up to use a UTF-8 code page.
   Same for Windows platforms.

FPC should seriously start ringing those alarm bells, as many programs
compiled with FPC 3.x are bound to hit these errors (BUGS). Valuable
data could get corrupted.

To all programmers, start using UnicodeString or UTF8String types only,
and everywhere!

Regards,
  Graeme



Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp



More information about the fpc-pascal mailing list