When you compile a program with the -Mtp switch, the compiler will attempt to mimic the Turbo
Pascal compiler in the following ways:
- Assigning a procedural variable doesn’t require an @ operator. One of the differences
between Turbo Pascal and Free Pascal is that the latter requires you to specify an
address operator when assigning a value to a procedural variable. In Turbo Pascal
compatibility mode, this is not required.
- Procedure overloading is disabled. If procedure overloading is disabled, the function
header doesn’t need to repeat the function header.
- Forward defined procedures don’t need the full parameter list when they are defined. Due to
the procedure overloading feature of Free Pascal, you must always specify the parameter list
of a function when you define it, even when it was declared earlier with Forward. In Turbo
Pascal compatibility mode, there is no function overloading; hence you can omit the
parameter list:
Procedure a (L : Longint); Forward;
...
Procedure a ; { No need to repeat the (L : Longint) }
begin
...
end;
- Recursive function calls are handled differently. Consider the following example:
Function expr : Longint;
begin
...
Expr:=L:
Writeln (Expr);
...
end;
In Turbo Pascal compatibility mode, the function will be called recursively when the writeln
statement is processed. In Free Pascal, the function result will be printed. In order to call
the function recursively under Free Pascal, you need to implement it as follows
:
Function expr : Longint;
begin
...
Expr:=L:
Writeln (Expr());
...
end;
- Any text after the final End. statement is ignored. Normally, this text is processed
too.
- You cannot assign procedural variables to untyped pointers; so the following is
invalid:
a: Procedure;
b: Pointer;
begin
b := a; // Error will be generated.
- The @ operator is typed when applied on procedures.
- You cannot nest comments.
Remark: The MemAvail and MaxAvail functions are no longer available in Free Pascal as of version 2.0. The
reason for this incompatibility follows:
On modern operating systems,
the idea of ”Available Free Memory” is not valid for an application. The reasons are:
- One processor cycle after an application asked the OS how much memory is free,
another application may have allocated everything.
- It is not clear what ”free memory” means: does it include swap memory, does it include
disk cache memory (the disk cache can grow and shrink on modern OS’es), does it
include memory allocated to other applications but which can be swapped out, etc.
Therefore, programs using MemAvail and MaxAvail functions should be rewritten so they no longer
use these functions, because it does not make sense any more on modern OS’es. There are 3
possibilities:
- Use exceptions to catch out-of-memory errors.
- Set the global variable ”ReturnNilIfGrowHeapFails” to True and check after each
allocation whether the pointer is different from Nil.
- Don’t care and declare a dummy function called MaxAvail which always returns
High(LongInt) (or some other constant).