Porting Turbo Pascal to Free Pascal
This document contains some information about differences between Free Pascal and Turbo Pascal 7.0. This list is not complete.
Assembler
- The default assembler uses an other syntax, but you can turn on the Intel styled assembler reader (which is what Turbo Pascal uses) using the -Rintel command line option or by adding {$asmmode intel} in your source.
- The 32 bit memory model requires a complete recoding of your assembler blocks.
Run time library
- To use the PORT array, add the Ports unit to you uses clause (only available under Dos/Go32v2 and Linux)
- You can access the realmode memory using MEM[seg:ofs] (as well as MemW and MemL) under Go32v2 only
- Ofs() returns a longint instead of a word
- The OVERLAY unit isn't available
- Turbo Vision is not (yet) available (copyright problems)
Preprocessor/Syntax
- If you use the -So command line switch (or add {$mode TP}in your source), the compiler will be put in Turbo Pascal compatibility mode, which will disable several of FPC's advanced features (like procedure overloading) to allow better compatibility with Turbo Pascal.
- Nested comments are allowed, but give a Note when found (disabled in TP mode)
Syntax
- FAR and NEAR are ignored
- To get the address of a procedure to assign it to a procedure variable you must use the @-operator (in TP mode, procedure variables work like in TP)
procedure p; begin end; var proc : procedure; begin proc:=@p; end;
Semantics
- Maximum parameter size which can be passed to a subroutine is 64K for the Intel version and 32K for the Motorola versions.
- Records are always aligned on word; use 'packed record' or {$PACKRECORDS 1} to get TP7 compatible records. A word of warning: use packed only if you absolutely need to, as non-alignment of fields may not work on non-Intel processors (and will slow down data access severly in all cases).
type r1=record a : byte; b : word; end; r2=packed record a : byte; b : word; end; begin writeln(sizeof(r1)); { outputs 4 } writeln(sizeof(r2)); { outputs 3 } end.
function a : longint; begin a:=12; while a>4 do begin {...} end; end;
function a : longint; begin a:=12; { v---- this is a recursive call } if a()>4 then begin {...} end; end;
function a : longint; begin a:=12; if a>4 then exit(a*67); end;
procedure x(v : longint);forward; procedure x; { this overloads the procedure x !!!!} begin { ... } end; { write instead: } procedure x(v : longint); begin { ... } end;
Others
- The command line parameters are different
- Not all compiler switches are fully implemented
- The units aren't binary compatible