Pascal through the dialects
last modified November 19, 2026 Free Pascal 3.2.2
Free Pascal is not one language but several dialects behind one compiler. The
same source file can be compiled as Turbo Pascal, as the default FPC dialect, as
ObjFPC, or as Delphi, and each mode accepts a different subset of the language.
The mode decides the default string type, the size of Integer,
whether Result exists, how procedural variables are assigned, and
whether a record can contain a class operator. This article
compiles the same programs in all four modes and shows where they diverge.
The four modes
A mode is selected on the command line with -M or in the source
with a {$mode ...} directive. The directive wins for the file it
appears in, so a legacy unit can keep {$mode tp} while the rest of
the project uses ObjFPC. The compiler does not merge the modes: a unit and the
program that uses it may be written in different dialects.
| Mode | Flag | Default string | Integer | Typical use |
|---|---|---|---|---|
| Turbo Pascal | -Mtp | ShortString | 2 bytes | DOS-era code, crt, old objects |
| FPC | -Mfpc | ShortString | 2 bytes | The compiler's original dialect |
| ObjFPC | -Mobjfpc | ShortString | 4 bytes | Classes, generics, modern units |
| Delphi | -Mdelphi | AnsiString | 4 bytes | Delphi source, direct method pointers |
The table describes the defaults, not the limits. ObjFPC becomes a fully modern
dialect with {$H+}, which turns string into an
AnsiString, and with mode switches for advanced records, type
helpers, and anonymous function syntax where the compiler supports it.
One program, four modes
The program below prints the size of a string variable and of
Integer. It has no {$mode} directive, so the
command-line flag decides everything. Compiling it four times produces four
different pairs of numbers from the same bytes of source.
program modes;
var
S: string;
begin
WriteLn('string: ', SizeOf(S));
WriteLn('Integer: ', SizeOf(Integer));
end.
Turbo Pascal and FPC mode agree: a string is a 256-byte
ShortString and an integer is 16 bits. ObjFPC keeps the short
string but widens Integer to 32 bits. Delphi mode makes
string a pointer-sized AnsiString and also uses a
32-bit integer.
$ fpc -Mtp modes.pas $ ./modes string: 256 Integer: 2 $ fpc -Mfpc modes.pas $ ./modes string: 256 Integer: 2 $ fpc -Mobjfpc modes.pas $ ./modes string: 256 Integer: 4 $ fpc -Mdelphi modes.pas $ ./modes string: 8 Integer: 4
Result and the function name
In all four modes a function can assign its result to its own name. Only
ObjFPC and Delphi also provide the Result identifier. The
following program therefore compiles everywhere, while the same body written
with Result := N * 2 fails in Turbo Pascal and FPC modes.
program resultname; function DoubleIt(N: Integer): Integer; begin DoubleIt := N * 2; end; begin WriteLn(DoubleIt(21)); end.
The function-name form is the portable one when a unit must compile in every
dialect. In a new ObjFPC program Result is clearer, especially in
a long function with several exits, and the compiler treats it as an alias for
the hidden result variable.
$ fpc -Mtp resultname.pas $ ./resultname 42
Procedural variables and the @ operator
Assigning a routine to a procedural variable is another point of divergence.
Turbo Pascal and Delphi accept the routine name directly. FPC and ObjFPC parse
the name as a call with no arguments and reject the assignment; the address
operator @ is required.
program procs; type TProc = procedure(N: Integer); procedure ShowDouble(N: Integer); begin WriteLn(N * 2); end; var P: TProc; begin P := ShowDouble; P(21); end.
Compiling the same file in ObjFPC produces the error below. Changing the
assignment to P := @ShowDouble makes it compile in every mode, so
the caret-free form is the one to keep when porting Delphi code.
$ fpc -Mobjfpc procs.pas procs.pas(11,8) Error: Wrong number of parameters specified for call to "ShowDouble" procs.pas(4,11) Error: Found declaration: ShowDouble(LongInt); procs.pas(14) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted
Operators inside records
Delphi mode allows a class operator inside a record, the syntax
Delphi uses for value types with arithmetic. ObjFPC rejects it there and
expects a top-level operator declaration after the type. Turbo
Pascal and FPC do not have record operators at all.
program opover;
type
TVec = record
X, Y: Integer;
class operator +(A, B: TVec): TVec;
end;
class operator TVec.+(A, B: TVec): TVec;
begin
Result.X := A.X + B.X;
Result.Y := A.Y + B.Y;
end;
var
A, B, C: TVec;
begin
A.X := 1; A.Y := 2;
B.X := 10; B.Y := 20;
C := A + B;
WriteLn(C.X, ' ', C.Y);
end.
The declaration and the implementation both sit inside the type in Delphi
syntax. In ObjFPC the operator body moves outside and the keyword
class is dropped; the
advanced records article shows both
forms side by side.
$ fpc -Mdelphi opover.pas $ ./opover 11 22
Choosing a mode
New code should use ObjFPC with {$H+}, because it has the widest
feature set and the largest body of examples. Delphi mode is the right choice
when the source must also compile in Delphi and uses its method pointers,
class operator, or direct procedural assignment. Turbo Pascal mode
exists for legacy units; it is not a good starting point for a new program.
The FPC dialect sits in between and is mostly interesting for the compiler's own sources. Whatever the choice, put the mode in the source rather than in a build script, so opening the file in another project cannot silently change its types. The Turbo Pascal and legacy code article covers the migration path in detail.
Source
Free Pascal Programmer's Guide
In this article we compiled one source file in Turbo Pascal, FPC, ObjFPC, and
Delphi modes, compared their string and integer sizes, and saw how
Result, procedural assignment, and record operators differ. The
Turbo Pascal and legacy code article applies
the same knowledge to an old unit.
Author
List all Pascal tutorials.