FPC New Features 2.6.0

From Free Pascal wiki
Jump to: navigation, search


About this page

Below you can find a list of new features introduced since the previous release, along with some background information and examples. Note that since svn trunk is by definition still under development, some of the features here may still change before they end up in a release version.

All systems


Better support for Delphi-compatible classes

  • Overview: Support has been added for nested types (including other classes), class variables and class-local constants.
  • Notes: Delphi-compatible.
  • More information: class_extensions_examples lists several examples that make use of these features.

Advanced record syntax

Enumerators in records

Support for class and record helpers

  • Overview: Support has been added for class and record helpers which allow you to add methods, properties and enumerators to classes and records without inheriting from them.
  • Notes: Delphi-compatible.
  • More information:

Generic records, arrays and procedural types

Scoped enumerations

Custom deprecated messages

  • Overview: Deprecated can now be applied to virtually any syntactic element (including constants and units), and it is also possible to specify a custom deprecation message.
  • Notes: Delphi-compatible
  • More information:
unit OldUnit deprecated 'Use NewUnit instead';
procedure OldRoutine; deprecated 'Use NewRoutine instead';

Support for the Objective-Pascal dialect

  • Overview: On Mac OS X, most system frameworks are written in Objective-C. While it is possible to interface them via a procedural API, this is not very convenient. For this reason, the Macintosh Pascal community has created a new dialect called Objective-Pascal that enables seamless interacting with Objective-C code.
  • Notes: This new dialect is currently only supported on Darwin-based platforms (including iOS) using the Apple Objective-C runtime. Patches to add support for the GNUStep runtime are welcome.
  • More information:
    • FPC_PasCocoa explains the basic language definitions.
    • FPC_PasCocoa/Differences explains some of the differences between Objective-Pascal and on the one hand Object Pascal, and on the other hand Objective-C.

Constref parameter modifier

  • Overview: A new parameter modifier called constref has been added, similar to the existing var, const and out ones. This modifier means that the compiler can assume that the parameter is constant, and that it must be passed by reference. Its most obvious usage is to translate const * parameters from C headers.
  • Notes: The main reason it was introduced was to enable writing a cross-platform interface for XPCOM, as explained on the User Changes 2.6.0 page. Note that in general, it should only be used for interfacing with external code or when writing assembler routines. In other cases, letting the compiler decide how to pass the parameter is more likely to result in optimal code on most platforms in the long term.
  • More information:
procedure test(constref l: longint);
  writeln('This parameter has been passed by reference, although the Pascal code does not really care about that: ',l);

Basic ISO Standard Pascal support

  • Overview: A language mode supporting ISO 7185 Standard Pascal has been added. It can be activated via the -Miso command line switch, or via the {$mode iso} compiler directive.
  • Notes: This support is not yet complete. In particular, no ISO Standard Pascal compatible I/O is available yet (get, put, ...)
  • More information: http://www.moorecad.com/standardpascal/standards.html

Support for nested procedure variables

  • Overview: It is now possible to define procedure variables that are assignment-compatible with nested procedures and functions. This feature is enabled by default in {$mode macpas} and {$mode iso}, and can be enabled in other syntax modes by adding {$modeswitch nestedprocvars} to your source file. Note that it is possible to also assign regular (non-nested) procedures/functions to a nested procedure variable, and to call them that way.
  • Notes: Enabling this feature changes the calling convention used for nested procedures/functions. This will break code from the Turbo Pascal era that uses nested procedures/functions as callbacks from collection iterators in the objects unit.
  • More information: A procedure variable type can hold a reference to nested routines in two cases:
    • when it is declared inline in the parameter list of another function/procedure (ISO-style declaration). This form of declaring procedure variable types is only available when nestedprocvars are enabled.
    • when it is declared as is nested, similar to of object for "procedure of object" types. Note that in this second case, it is possible to write invalid code: if you assign a nested routine to nested procedure variable and then exit the nested routine's parent stack frame, calling the nested procedure variable will result in undefined bahaviour.

Support for non-local goto's

  • Overview: It is now possible to goto to a label defined in another procedure, e.g. to quickly exit from a deeply nested procedure to a less deeply nested one.
  • Notes: Enabled by default in ISO and MacPas syntax modes, can be enabled in other modes via {$modeswitch nonlocalgoto}. It is not possible to use a non-local goto to jump over stack frames that require finalisation (e.g., when they contain reference counted types).
  • More information: http://svn.freepascal.org/svn/fpc/trunk/tests/test/tmacnonlocalgoto.pp

Support for &-escaping of keywords

Support for univ parameters in MacPas mode

  • Overview: Previous FPC versions simply ignored the univ qualifier for parameters. Now, FPC will properly parse it and interpret it like other Mac Pascal compilers: it allows passing any parameter whose size matches the size of the declared parameter.
  • Notes: Only enabled in {$mode macpas}. Abusing this feature can easily result in crashes or corrupted data in case the declared parameter type and the actual parameter have to be passed to the subroutine in different ways according to the calling convention. In general, this feature should only be used to port legacy code.
  • More information: http://bugs.freepascal.org/view.php?id=15777

CExtended floating point type

  • Overview: This type is the same as the regular extended type in terms of precision, but it conforms to the properties/behaviour of the equivalent of the Extended type in C. In practice, this means that CExtended corresponds to long double on i386 and x86_64 platforms that support an 80 bits extended type, and to double on other platforms. This is mainly required for fields in records that are translated from C in order to guarantee proper field alignments, and also for parameters to C routines.
  • Notes: At this time, FPC does not support an equivalent of C's long double type on platforms other than the ones mentioned above. Since Extended is an alias for Double on these other platforms in FPC, CExtended is also an alias for double there.
  • More information: /

SAR intrinsics

  • Overview: Support has been added for shift arithmetic right (SAR) intrinsics.
  • Notes: Unlike the SHL and SHR operators, SAR is not implemented as an operator but as an intrinsic. It is also defined using different names for different integer sizes to prevent unexpected results when applying it to expressions.
  • More information: http://svn.freepascal.org/svn/fpc/trunk/tests/test/cg/tsar1.pp

ROL/ROR intrinsics

  • Overview: Support has been added for ROL (Rotate Overflow Left) and ROR (Rotate Overflow Right) intrinsics. These shift a value left or right, inserting bits that were shifted out at the other side of the value.
  • Notes: Just like for the SAR intrinsic, separate versions have been added for different integer sizes in order to prevent any ambiguities.
  • More information: http://svn.freepascal.org/svn/fpc/trunk/tests/test/trox1.pp

Bitscan intrinsics

Boolean16, Boolean32 and Boolean64 types

  • Overview: Support has been added for Boolean16, Boolean32 and Boolean64 types
  • Notes: These new boolean types behave like the standard pascal type Boolean except that their size is 2, 4 or 8 bytes. This is usefull to interface with some libraries.
  • More information: The existing WordBool, LongBool and QWordBool types assume false=0 and true<>0. With the new types false=0 and true=1, while any other value is invalid.

ARM systems

Support for VFPv2 and VFPv3

  • Overview: Support has been added for the ARM Vector Floating Point (VFP) units versions 2 and 3. This is the floating point unit that's usually included on, a.o., Cortex-A8 and Cortex-A9 family CPUs, and in the iOS-based devices.
  • Notes: When targeting a CPU that implements the ARMv6 or later architecture, you must also use -Cparmv6 at the same time. The reason is that saving/restoring the VFP unit's context must occur using different instructions prior to ARMv6. -Cparmv6 is enabled by default for iOS targets though, because all such devices are at least ARMv6. Additionally, FPC only supports the so-called softfp ABI for VFP: the VFP unit is used to perform the calculations, but the used calling convention to pass floating point values is the same as for soft-float.
  • More information: Activate using the -Cfvfpv2 resp. -Cfvfpv3 command line parameters.

Support for Thumb-2

  • Overview: Support has been added to generate Thumb-2 code for the ARMv7-M architecture as implemented in the Cortex-M3 family.
  • Notes: This architecture is currently only supported for no-OS targets (embedded); it does not yet work for iOS or Linux.
  • More information: Activate using the -Cparmv7m or -Cpcortexm3 command line parameters.

IA32/i386 systems

Support for the iPhoneSim target

  • Overview: As of Xcode 3.2.4, the iPhoneSimulator target uses a different Objective-C ABI than regular i386 code. Therefore a new target called iphonesim was added to the compiler.
  • Notes: If you are still using an earlier version of Xcode to develop iPhoneSimulator-based code, use the regular Darwin/i386 target.
  • More information: use the -Tiphonesim command line parameter to select this target. When compiling the FPC packages for this target, this will also compile a special version of MacOSAll that only contains APIs available for this target.

See also

Personal tools