Free Pascal is designed to be cross-platform. This means that the basic RTL units are usable on all
platforms, and the compiler behaves the same on all platforms (as far as possible). The
Object Pascal langauge is the same on all platforms. Nevertheless, FPC comes with a lot
of units that are not portable, but provide access to all possibilities that a platform
provides.
The following are some guidelines to consider when writing portable code:
- Avoid system-speci c units. The system unit, the objects and classes units and the
SysUtils unit are guaranteed to work on all systems. So is the DOS unit, but that is
deprecated.
- Avoid direct hardware access. Limited, console-like Hardware access is available for
most platforms in the Video, Mouse and Keyboard units.
- Do not use hard-coded lename conventions. See below for more information on this.
- Make no assumptions on the internal representation of types. Various processors store
information in di erent ways ('endianness').
- If system-speci c functionality is needed, it is best to separate this out in a single unit.
Porting e orts will then be limited to re-implementing this unit for the new platform.
- Don't use assembler, unless you have to. Assembler is processor speci c. Some
instructions will not work even on the same processor family.
- Do not assume that pointers and integers have the same size. They do on an intel 32-bit
processor, but not necesarily on other processors. The PtrInt type is an alias for the
integer type that has the same size as a pointer. SizeInt is used for all size-related
issues.
The system unit contains some constants which describe le access on a system:
-
LineEnding
- A character or string which describes the end-of-line marker used on the
current platform. Commonly, this is one of #10, #13#10 or #13.
-
LFNSupport
- A boolean that indicates whether the system supports long lenames (i.e. is
not limited to MS-DOS 8.3 lenames).
-
DirectorySeparator
- is the character which acts as a separator between directory parts of
a path.
-
DriveSeparator
- for systems that supports driveletters, this is the character that is used
to separate the drive indication from the path..
-
PathSeparator
- the character used to separate items in a list (notably, a PATH).
-
maxExitCode
- The maximum value for a process exitcode.
-
MaxPathLen
- The maximum length of a lename, including a path.
-
FileNameCaseSensitive
- a boolean that indicates whether lenames are handled case
sensitively.
-
UnusedHandle
- a value used to indicate an unused/invalid le handle.
-
StdInputHandle
- the value of the standard input le handle. This is not always zero, as is
commonly the case on Unices.
-
StdOutputHandle
- the value of the standard input le handle. This is not always 1, as is
commonly the case on Unices.
-
StdErrorHandle
- the value of the standard input le handle. This is not always 2, as is
commonly the case on Unices.
-
CtrlZMarksEOF
- a boolean that indicates whether the #26 character marks the end of a
le. (an old MS-DOS convention)