Free Pascal
Programmers’ manual


____________________________________________________________________
Programmers’ manual for Free Pascal, version 1.0.8
Document version 1.9
May 2003

Michaël Van Canneyt

____________________________________________________________________________
Contents
List of Tables
 0.1 About this document
1 Compiler directives
 1.1 Local directives
   $A or $ALIGN : Align Data
   $ASMMODE : Assembler mode (Intel 80x86 only)
   $B or $BOOLEVAL : Complete boolean evaluation
   $C or $ASSERTIONS : Assertion support
   $DEFINE : Define a symbol
   $ELSE : Switch conditional compilation
   $ENDIF : End conditional compilation
   $ERROR : Generate error message
   $F : Far or near functions
   $FATAL : Generate fatal error message
   $GOTO : Support Goto and Label
   $H or $LONGSTRINGS : Use AnsiStrings
   $HINT : Generate hint message
   $HINTS : Emit hints
   $IF : Start conditional compilation
   $IFDEF Name : Start conditional compilation
   $IFNDEF : Start conditional compilation
   $IFOPT : Start conditional compilation
   $INFO : Generate info message
   $INLINE : Allow inline code.
   $I or $IOCHECKS : Input/Output checking
   $I or $INCLUDE : Include file
   $I or $INCLUDE : Include compiler info
   $I386__ XXX : Specify assembler format (Intel 80x86 only)
   $L or $LINK : Link object file
   $LINKLIB : Link to a library
   $M or $TYPEINFO : Generate type info
   $MACRO : Allow use of macros.
   $MAXFPUREGISTERS : Maximum number of FPU registers for variables (Intel 80x86 only)
   $MESSAGE : Generate info message
   $MMX : Intel MMX support (Intel 80x86 only)
   $NOTE : Generate note message
   $NOTES : Emit notes
   $OUTPUT__ FORMAT : Specify the output format
   $P or $OPENSTRINGS : Use open strings
   $PACKENUM : Minimum enumeration type size
   $PACKRECORDS : Alignment of record elements
   $Q $OVERFLOWCHECKS: Overflow checking
   $R or $RANGECHECKS : Range checking
   $SATURATION : Saturation operations (Intel 80x86 only)
   $SMARTLINK : Use smartlinking
   $STATIC : Allow use of Static keyword.
   $STOP : Generate fatal error message
   $T or $TYPEDADDRESS : Typed address operator (@)
   $UNDEF : Undefine a symbol
   $V or $VARSTRINGCHECKS : Var-string checking
   $WAIT : Wait for enter key press
   $WARNING : Generate warning message
   $WARNINGS : Emit warnings
   $X or $EXTENDEDSYNTAX : Extended syntax
 1.2 Global directives
   $APPTYPE : Specify type of application (Win32 and AmigaOS only)
   $D or $DEBUGINFO : Debugging symbols
   $DESCRIPTION : Application description
   $E : Emulation of coprocessor
   $G : Generate 80286 code
   $INCLUDEPATH : Specify include path.
   $L or $LOCALSYMBOLS : Local symbol information
   $LIBRARYPATH : Specify library path.
   $M or $MEMORY : Memory sizes
   $MODE : Set compiler compatibility mode
   $N : Numeric processing
   $O : Overlay code generation
   $OBJECTPATH : Specify object path.
   $S : Stack checking
   $UNITPATH : Specify unit path.
   $W or $STACKFRAMES : Generate stackframes
   $Y or $REFERENCEINFO : Insert Browser information
2 Using conditionals, messages and macros
 2.1 Conditionals
   Predefined symbols
 2.2 Messages
 2.3 Macros
3 Using Assembly language
 3.1 Intel 80x86 Inline assembler
   Intel syntax
   AT&T Syntax
 3.2 Motorola 680x0 Inline assembler
 3.3 Signaling changed registers
4 Generated code
 4.1 Units
 4.2 Programs
5 Intel MMX support
 5.1 What is it about?
 5.2 Saturation support
 5.3 Restrictions of MMX support
 5.4 Supported MMX operations
 5.5 Optimizing MMX support
6 Code issues
 6.1 Register Conventions
   accumulator register
   accumulator 64-bit register
   float result register
   self register
   frame pointer register
   stack pointer register
   scratch registers
   Processor mapping of registers
 6.2 Name mangling
   Mangled names for data blocks
   Mangled names for code blocks
   Modifying the mangled names
 6.3 Calling mechanism
 6.4 Nested procedure and functions
 6.5 Constructor and Destructor calls
   objects
   classes
 6.6 Entry and exit code
   Intel 80x86 standard routine prologue / epilogue
   Motorola 680x0 standard routine prologue / epilogue
 6.7 Parameter passing
   Parameter alignment
 6.8 Processor limitations
7 Linking issues
 7.1 Using external code and variables
   Declaring external functions or procedures
   Declaring external variables
   Declaring the calling convention modifier
   Declaring the external object code
 7.2 Making libraries
   Exporting functions
   Exporting variables
   Compiling libraries
   Unit searching strategy
 7.3 Using smart linking
8 Memory issues
 8.1 The memory model.
 8.2 Data formats
   integer types
   char types
   boolean types
   enumeration types
   floating point types
   pointer types
   string types
   set types
   array types
   record types
   object types
   class types
   file types
   procedural types
 8.3 Data alignment
   Typed constants and variable alignment
   Structured types alignment
 8.4 The heap
   Heap allocation strategy
   The HeapError variable
   The heap grows
   Debugging the heap
   Writing your own memory manager
 8.5 Using dos memory under the Go32 extender
9 Resource strings
 9.1 Introduction
 9.2 The resource string file
 9.3 Updating the string tables
 9.4 GNU gettext
 9.5 Caveat
10 Optimizations
 10.1 Non processor specific
   Constant folding
   Constant merging
   Short cut evaluation
   Constant set inlining
   Small sets
   Range checking
   And instead of modulo
   Shifts instead of multiply or divide
   Automatic alignment
   Smart linking
   Inline routines
   Stack frame omission
   Register variables
 10.2 Processor specific
   Intel 80x86 specific
   Motorola 680x0 specific
 10.3 Optimization switches
 10.4 Tips to get faster code
 10.5 Tips to get smaller code
11 Programming shared libraries
 11.1 Introduction
 11.2 Creating a library
 11.3 Using a library in a pascal program
 11.4 Using a pascal library from a C program
12 Using Windows resources
 12.1 The resource directive $$ R
 12.2 Creating resources
 12.3 Using string tables.
 12.4 Inserting version information
 12.5 Inserting an application icon
 12.6 Using a pascal preprocessor
A Anatomy of a unit file
 A.1 Basics
 A.2 reading ppufiles
 A.3 The Header
 A.4 The sections
 A.5 Creating ppufiles
B Compiler and RTL source tree structure
 B.1 The compiler source tree
 B.2 The RTL source tree
C Compiler limits
D Compiler modes
 D.1 FPC mode
 D.2 TP mode
 D.3 Delphi mode
 D.4 GPC mode
 D.5 OBJFPC mode
E Using fpcmake
 E.1 Introduction
 E.2 Functionality
 E.3 Usage
 E.4 Format of the configuration file
   clean
   compiler
   Default
   Dist
   Install
   Package
   Prerules
   Requires
   Rules
   Target
 E.5 Programs needed to use the generated makefile
 E.6 Variables that affect the generated makefile
   Directory variables
   Compiler command-line variables
 E.7 Variables set by fpcmake
   Directory variables
   Target variables
   Compiler command-line variables
   Program names
   File extensions
   Target files
 E.8 Rules and targets created by fpcmake
   Pattern rules
   Build rules
   Cleaning rules
   archiving rules
   Installation rules
   Informative rules
F Compiling the compiler
 F.1 Introduction
 F.2 Before starting
 F.3 Compiling using make
 F.4 Compiling by hand
   Compiling the RTL
   Compiling the compiler
G Compiler defines during compilation
H Operating system specific behavior