FPC New Features 3.0

Below you can find a list of new features introduced since the previous release, along with some background information and examples.

All systems

Language

Delphi-like namespaces units

• Overview: Support has been added for unit names with dots.
• Notes: Delphi-compatible.
• More information: Unit names with dots create namespace symbols which always have a precedence over unit names in an identifier search.

Dynamic array constructors

• Overview: Support has been added for constructing dynamic arrays with class-like constructors.
• Notes: Delphi-compatible.
• More information: Only constructor name 'CREATE' is valid for dynamic arrays.
• Examples: SomeArrayVar := TSomeDynArrayType.Create(value1, value2)

New compiler intrinsic Default

• Overview: A new compiler intrinsic Default has been added which allows you get a correctly initialized value of a type which is given as parameter. It can also be used with generic type parameters to get a default value of the type.
• Notes: Delphi-compatible.
• More information: In simple terms the value returned by Default will be initialized with zeros. The Default intrinsic is not allowed on file types or records/objects/arrays containing such types (Delphi ignores file types in sub elements).
• Examples:
type
TRecord = record
i: LongInt;
s: AnsiString;
end;

var
i: LongInt;
o: TObject;
r: TRecord;
begin
i := Default(LongInt); // 0
o := Default(TObject); // Nil
r := Default(TRecord); // ( i: 0; s: '')
end.
type
generic TTest<T> = class
procedure Test;
end;

procedure TTest.Test;
var
myt: T;
begin
myt := Default(T); // will have the correct Default if class is specialized
end;

Support for type helpers

• Overview: Support has been added for type helpers which allow you to add methods and properties to primitive types. They require modeswitch TypeHelpers to be set.
• Notes: In mode Delphi it's implemented in a Delphi-compatible way using record helper for declaration, while the modes ObjFPC and MacPas use type helper. The modeswitch TypeHelpers is enabled by default only in mode Delphi and DelphiUnicode.

Support for codepage-aware strings

• Overview: Ansistrings have been made codepage-aware. This means that every ansistring now has an extra piece of meta-information that indicates the codepage in which the characters of that string are encoded.
• Notes: Delphi-compatible (2009 and later).

New delphiunicode syntax mode

• Overview: The new syntax mode {$mode delphiunicode} combines the behaviour of {$mode delphi} with functionality that is specific to Delphi versions that switched to UnicodeString by default (Delphi 2009 and later).

Shortcuts to speed up floating point calculations

• Overview: The compiler can now in some cases (which may be extended in the future) take shortcuts to optimize the evaluation of floating point expressions, at the expense of potentially reducing the precision of the results.
• Notes: Examples of possible optimizations include turning divisions by a value into multiplications with the reciprocal value (not yet implemented), and reordering the terms in a floating point expression.
• More information: This optimization is only enabled by default at the new optimization level -O4, which enables optimizations that may have (unforeseen) side effects. You can also enable the optimization individually using the -Oofastmath command line option, or by adding {$optimization fastmath} to your source file. Constant propagation • Overview: The compiler can now, to a limited extent, propagate constant values across multiple statements in function and procedure bodies. • Notes: Constant propagation can cause range errors that would normally manifest themselves at runtime to be detected at compile time already. • More information:This optimization is enabled by default at optimization level -O3 and higher. You can also enable the optimization individually using the -Ooconstprop command line option, or by adding {$optimization constprop} to your source file.

• Overview: The compiler can now, to a limited extent, remove stores to local variables and parameters if these values are not used before they are overwritten.
• Notes: The use of this optimization requires that data flow analysis (-Oodfa) is enabled. It can help in particular with cleaning up instructions that have become useless due to constant propagation.
• More information: This optimization is currently not enabled by default at any optimization level because -Oodfa is still a work in progress. You can enable the optimization individually using the -Oodeadstore command line option, or by adding {\$optimization deadstore} to your source file.

Node dfa for liveness analysis

• Overview: The compiler can now perform static data flow analysis (dfa) to determine data liveness.
• Notes: This analysis is only enabled when -O3 is used.
• More information: Warnings about uninitialized variables are more exact when using dfa compared with the previous approach. However, the current dfa approach is static and non-global, so one might get false positives:
  var
b : boolean;
i : longint;
begin
if b then
i:=1;
writeln;
if b then
writeln(i);
end.

In this case, the compiler warns about i being uninitialized. While some cases like the case above could be detected and the warning could be prevent, this does no apply if b is a function. To workaround this, add an assignment to i at the entry of the subroutine body.

The same applies to functions/procedures:

  var
i : longint;
procedure p;
begin
i:=1;
end;
begin
p;
writeln(i);
end.

The current dfa approach works only intra-procedurally instead of globally, so the above case cannot yet be handled correctly. The compiler does not see that i is initialized. To work around this, add an assignment to i at the entry of the outer subroutine body.

Units and packages

TDBF support for Visual FoxPro files

• Overview: TDBf now has explicit support for Visual FoxPro (tablelevel 30) files, including the VarBinary and VarChar datatypes.
• Notes: TDBF version increased to 7.0.0.
• More information: The code does not support .dbc containers, only freestanding dbfs. It does not support (and quite likely will never support) .cdx index files.

Additionally, TDBf is now included in the database test suite and has received several fixes (including better Visual FoxPro codepage support).

Bufdataset supports ftAutoInc fields

• Overview: Bufdataset now has support for automatically increasing ftAutoinc field values.

TDBF, bufdataset (and descendents such as TSQLQuery) allow escaped delimiters in string expression filter

• Overview: filters that contain string expressions should be quoted (using either ' or "). However, having the same quotes within the filter was not parsed as there was no support for escaping quotes in the string

Support has been added for escaping quotes to allow this.

• Notes: Double up the delimiter within the string to escape the delimiter. Example:
Filter:='(NAME=''O''''Malley''''s "Magic" Hammer'')';
//which gives
//(NAME='O''Malley''s "Magic" Hammer')
//which will match record
//O'Malley's "Magic" Hammer

TODBCConnection (odbcconn) Support for 64 bit ODBC

• Overview: 64 bit ODBC support has been added.
• Notes: if you use unixODBC version 2.3 or higher on Linux/Unix, the unit has to be (re)compiled with -dODBCVER352 to enable 64 bit support

TZipper support for zip64 format

• Overview: TZipper now supports the zip64 extensions to the zip file format: > 65535 files and > 4GB file size (bug #23533). Related fixes also allow path/filenames > 255 characters.
• Notes: the zip64 format will automatically be used if the number or size of files involved exceed the limits of the old zip format. Note that there still are 2GB limits on streams as used in extraction/compression. Zip64 is unrelated to the processor type/bitness (such as x86, x64, ...).

Multiple codepage and unicode support for most file-related RTL routines

• Overview: Most file-related routines from the system and sysutils units have been made codepage-aware: they now accept ansistrings encoded in arbitrary codepages as well as unicodestrings, and will convert these to the appropriate codepage before calling OS APIs.
• Notes: /
• More information: Detailed list of all related changes to the RTL.

SQL parser/generator improvements

• Overview: The SQL parser/generator in packages/fcl-db/src/sql has been improved:
• Notes: N/A
• Support for FULL [OUTER] JOIN; optional OUTER in LEFT OUTER and RIGHT OUTER JOIN
• support table.column notation for fields like SELECT A.B FROM MYTABLE or SELECT B FROM MYTABLE ORDER BY C.D
• Small improvements (e.g. in array datatype access) that allow the parser to parse the Firebird employee sample database DDL. Note: there is no support for isql SET TERM statements, so isql DDL dumps containing stored procedures/triggers with semicolons can still not be processed properly

Tools and miscellaneous

New Pas2jni utility

• Overview: The new pas2jni utility generates a JNI (Java Native Interface) bridge for Pascal code. This enables Pascal code (including classes and other advanced features) to be easily used from Java programs.
• Notes: The following Pascal features are supported by pas2jni: function/procedure, var/out parameters, class, record, property, constant, enum, TGuid type, pointer type, string types, all numeric types

(Mac) OS X/iOS

New iosxlocale unit

• Overview: The new unit called iosxlocale can be used to initialise the DefaultFormatSettings and other related locale information in the sysutils unit based on the settings in the (Mac) OS X System Preferences or the iOS Settings app.
• Notes: The clocale unit, which also works on (Mac) OS X and iOS, instead gets its information from the Unix-layer. This information depends on the contents of the LC_ALL, LC_NUMERIC etc environment variables (see man locale for more information). Adding both clocale and iosxlocale to the uses clause will cause the second in line to overwrite the settings set by the first one.

New compiler targets

Support for the Java Virtual Machine and Dalvik targets

• Overview: Support has been added for generating Java byte code as supported by the Java Virtual Machine and by the Dalvik (Android) virtual machine.
• Notes: Not all language features are supported for these targets.

Support for the AIX target

• Overview: Support has been added for the AIX operating system. Both PowerPC 32bit and 64bit are supported, except that at this time the resource compiler does not yet work for ppc64.
• Notes: AIX 5.3 and later are supported.

Support for the 16-bit real mode MS-DOS target

• Overview: Support has been added for the 16-bit real mode MS-DOS target. Multiple memory models are supported (including ones, not supported by TP/BP)
• Notes: Open Watcom binutils (wlib and wlink) are required. Crosscompilation from go32v2 still has issues, due to lack of long file name support in Open Watcom's binutils and incompatibilities between Open Watcom's dos extender and the GO32 dos extender.

Support for the Android target

• Overview: Support has been added for the Android target. Supported CPUs: ARM, x86, MIPS.
• Notes: You need to build a cross-compiler from FPC sources to be able to compile for the Android target.

Support for the armhf EABI

• Overview: Support has been added for the armhf EABI.
• Notes: This support was already available in some patched FPC distribution by Debian GNU/Linux, but now it is officially supported.
• More information: To bootstrap a compiler with armhf support, the compiler must be compiled with -dFPC_ARMHF. An armhf compiler compiling itself will automatically create a new armhf compiler.

Support for the AROS target

• Overview: Support has been added for the AROS target. Supports: i386-ABIv0.
• Notes: You need to build a cross-compiler from FPC sources to be able to compile for the AROS target (requires collect-aros to support binutils). A native compiler for AROS is available.