Difference between revisions of "local compiler directives"

From Free Pascal wiki
Jump to navigationJump to search
(Next paragraph translated.)
 
(29 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 
{{local compiler directives}}
 
{{local compiler directives}}
__TOC__
 
Local directives may be used more then once in a unit or program.
 
  
==Local compiler direvtives==
+
Local [[Compiler directive|compiler directives]] may be used more than once in a Pascal [[Source code|source code]] file.
*[[sAlign/de|$A and $ALIGN]] determines the of alignment of data in records.
 
*[[sA/de|$A1, $A2,$A4 and $A8]] determines the of alignment of data in records. Has the same effect as the directive $PACKRECORDS.
 
*[[sBooleval/de|$B or $BOOLEVAL]] enables short-cut evaluation of boolean values.
 
*[[sAssertions/de|$C or $ASSERTIONS]] supports debugging.
 
*[[sBitpacking/de|$BITPACKING]] enables bit-wise packing of records.
 
*[[sCalling/de|$CALLING]] determines calling-convention of routines.
 
*[[sCheckpointer/de|$CHECKPOINTER]] checks validity of pointers.
 
*[[sCodealign/de|$CODEALIGN]] determines the code-aligning in memory.
 
*[[sCoperators/de|$COPERATORS]] enables usage of operatores similar to conventions in the C language.
 
*[[sDefine/de|$DEFINE or $DEFINEC]] enables definition of own symbols.
 
*[[sExtendedsym/de|$EXTENDEDSYM]] ignored by compiler.
 
*[[sFar/de|$F]] ignored by compiler.
 
*[[sFputype/de|$FPUTYPE]] compiles according to FPU type
 
*[[sGoto/de|$GOTO]] enables Goto and Label
 
*[[sH/de|$H or $LONGSTRINGS]] determines string type for reserved word [[string]].
 
*[[sHppemit/de|$HPPEMIT]] ignored by compiler.
 
*[[sImplicitexeptions/de|$IMPLICITEXCEPTIONS]] helps to avoid memory leaks.
 
*[[sInline/de|$INLINE]] copies procedures to the place, where they have been called from.
 
*[[sInterfaces/de|$INTERFACES]] determines interface type.
 
*[[sIochecks/de|$I or $IOCHECKS]] enables checking of input/output.
 
*[[sIncludefile/de|$I or $INCLUDE]] includes file in compilation.
 
*[[sIncludecompilerinfo/de|$I or $INCLUDE]] included certein compiler information.
 
*[[sWritableconst/de|$J or $WRITEABLECONST]] enables run-time assigning of values to typed constants.
 
*[[sLink/de|$L or $LINK]] inserts object file during linking.
 
*[[sLinklib/de|$LINKLIB]] inserts library during linking.
 
*[[sTypeinfo/de|$M or $TYPEINFO]] creates RTTI
 
*[[sMacro/de|$MACRO]] enables usage of macros.
 
*[[sMinenumsize/de|$MINENUMSIZE]] for Delphi-compatibility, see [[sPackenum/de|$PACKENUM or $Z]]
 
*[[sMinfpconstprec/de|$MINFPCONSTPREC]] sets minimum accuracy of floating point operations.
 
*[[sNodefine/de|$NODEFINE]] ignored by compiler.
 
*[[sObjectchecks/de|$OBJECTCHECKS]] checks usage of pointer to self.
 
*[[sOptimization/de|$OPTIMIZATION]] switches on certain optimizations.
 
*[[sOutput_format/de|$OUTPUT_FORMAT]] determines output format of object file.
 
*[[sPackenum/de|$PACKENUM or $Z]] enables packing of compiler enumerations.
 
*[[sPackrecords/de|$PACKRECORDS]] determines alignment of records in memory.
 
*[[sPackset/de|$PACKSET]] determines packing of sets.
 
*[[sPop/de|$POP]] recreates saved compiler settings.
 
*[[sPush/de|$PUSH]] saves current compiler settings.
 
*[[sOverflowchecks/de|$OVERFLOWCHECKS]] checkes integer variables for overflow.
 
*[[sRangechecks/de|$R or $RANGECHECKS]] checks overflow of index in compound variables.
 
*[[sResource/de|$R or $RESOURCE]] inserts resource file.
 
*[[sStatic/de|$STATIC]] enable usage of the reserved word static.
 
*[[sTypedadress/de|$T or $TYPEDADDRESS]] determines, if the address operator @ delivers a typed or untyped pointer.
 
*[[sUndef/de|$UNDEF]] undefines symbol.
 
*[[sVarstringchecks/de|$V or $VARSTRINGCHECKS]] enables checking of assignments to string variables.
 
*[[sStackframes/de|$W or $STACKFRAMES]] determines conditions for the creation of stack frames.
 
*[[sWait/de|$WAIT]] waits with execution until the enter key has been pressed.
 
  
==Conditional compilation==
+
== Syntax ==
*[[sElse/de|$ELSE]] defines alternative path in conditional compilation
+
* <syntaxhighlight lang="pascal" inline>{$cOperators}</syntaxhighlight> enables usage of [[Operator|operators]] similar to conventions of in the [[Pascal for C users|C]] language.
*[[sElseIf/de|$ELSEIF]] defines alternative and new branch conditional compilation
+
* [[sGoto|<syntaxhighlight lang="pascal" inline>{$goto}</syntaxhighlight>]] enables [[Goto|<syntaxhighlight lang="pascal" inline>goto</syntaxhighlight>]] and [[Label|<syntaxhighlight lang="pascal" inline>label</syntaxhighlight>]].
*[[sEndif/de|$ENDIF]] defines end of conditional compilation
+
* <syntaxhighlight lang="pascal" inline>{$inline}</syntaxhighlight> allows the [[Inline|<syntaxhighlight lang="pascal" inline>inline</syntaxhighlight>]] [[modifier]].
*[[sIf/de|$IF]] Begin of conditional compilation
+
* [[$H|<syntaxhighlight lang="pascal" inline>{$LongStrings}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$H}</syntaxhighlight>]] determines the data type referenced by the reserved word [[String|<syntaxhighlight lang="pascal" inline>string</syntaxhighlight>]].
*[[sIfdef/de|$IFDEF]] Begin of conditional compilation
+
* <syntaxhighlight lang="pascal" inline>{$macro}</syntaxhighlight> enables usage of [[Macros|macros]].
*[[sIfndef/de|$IFNDEF]] Begin of conditional compilation
+
* [[$scopedEnums|<syntaxhighlight lang="pascal" inline>{$scopedEnums}</syntaxhighlight>]] whether enumeration type members have to be referred to by the data types name as a scope. (since [[FPC New Features 2.6.0#Scoped enumerations|FPC 2.6.0]])
*[[sIfopt/de|$IFOPT]] Begin of conditional compilation
+
* [[$static|<syntaxhighlight lang="pascal" inline>{$static}</syntaxhighlight>]] enable usage of the reserved word <syntaxhighlight lang="delphi" inline>static</syntaxhighlight> (until [[User Changes 2.6.0#The Static modifier is now always enabled|FPC 2.6.0]]).
 +
* [[$typedAddress|<syntaxhighlight lang="pascal" inline>{$typedAddress}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$T}</syntaxhighlight>]] determines, if the address operator [[@|<syntaxhighlight lang="pascal" inline>@</syntaxhighlight>]] results in a typed or untyped pointer.
 +
* [[$varStringChecks|<syntaxhighlight lang="pascal" inline>{$varStringChecks}</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>{$V}</syntaxhighlight>]] enables strict checking of assignment compatibility of string variables.
 +
* [[$writableConst|<syntaxhighlight lang="pascal" inline>{$writableConst}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$J}</syntaxhighlight>]] enables assignment of values to typed [[Constant|constants]] during [[runtime|run-time]].
  
''The following text is still to be translated to English:''
+
== Data layout ==
 +
* [[$A|<syntaxhighlight lang="pascal" inline>{$align}</syntaxhighlight>]] and [[$A|<syntaxhighlight lang="pascal" inline>{$A}</syntaxhighlight>]] determine the alignment of data in records
 +
* [[$Bitpacking|<syntaxhighlight lang="pascal" inline>{$bitpacking}</syntaxhighlight>]] determines, whether <syntaxhighlight lang="pascal" inline>packed</syntaxhighlight> is interpreted as <syntaxhighlight lang="pascal" inline>bitpacked</syntaxhighlight>.
 +
* [[$codeAlign|<syntaxhighlight lang="pascal" inline>{$codeAlign}</syntaxhighlight>]] determines the code-alignment in memory.
 +
* <syntaxhighlight lang="pascal" inline>{$minEnumSize}</syntaxhighlight> recognized for Delphi-compatibility and has the same effect as the <syntaxhighlight lang="pascal" inline>{$packEnum}</syntaxhighlight> directive.
 +
* [[$minFPConstPrec|<syntaxhighlight lang="pascal" inline>{$minFPConstPrec}</syntaxhighlight>]] sets the minimum accuracy floating-point constants are stored at.
 +
* [[$packEnum|<syntaxhighlight lang="pascal" inline>{$packEnum}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$Z}</syntaxhighlight>]] enables packing of enumeration types.
 +
* [[$packRecords|<syntaxhighlight lang="pascal" inline>{$packRecords}</syntaxhighlight>]] determines alignment of [[Record|records]] in memory.
 +
* [[$packSet|<syntaxhighlight lang="pascal" inline>{$packSet}</syntaxhighlight>]] determines packing of [[Set|sets]].
  
==Self-defined compiler warnings, messages and hints==
+
== Code generation ==
*[[sError/de|$ERROR]] display a self-defined error message.
+
* [[$boolEval|<syntaxhighlight lang="pascal" inline>{$boolEval}</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>{$B}</syntaxhighlight>]] controls short-cut evaluation of Boolean expressions
*[[sFatal/de|$FATAL]] display a self-defined fatal error message.
+
* [[$Assertions|<syntaxhighlight lang="pascal" inline>{$assertions}</syntaxhighlight>]] or <syntaxhighlight lang="pascal" inline>{$C}</syntaxhighlight> control, whether [[assert|<syntaxhighlight lang="pascal" inline>assert</syntaxhighlight> statements]] are compiled into the [[Executable program|executable program]]
*[[sHint/de|$HINT]] displays a self-defined hint.
+
* [[$calling|<syntaxhighlight lang="pascal" inline>{$calling}</syntaxhighlight>]] determines the calling conventions for routines.
*[[sHints/de|$HINTS]] enables self-defined hints.
+
* [[$checkPointer|<syntaxhighlight lang="pascal" inline>{$checkPointer}</syntaxhighlight>]] in conjunction with [[heaptrc|<syntaxhighlight lang="text" inline>‑gh</syntaxhighlight>]] inserts checks ascertain validity of [[Pointer|pointers]].
*[[sInfo/de|$INFO]] display a self-defined information message
+
* [[$FPUtype|<syntaxhighlight lang="pascal" inline>{$FPUType}</syntaxhighlight>]] compiles according to FPU type.
*[[sMessage/de|$MESSAGE]] creates a self-defined information message
+
* [[$ieeeERRORS|<syntaxhighlight lang="pascal" inline>{$ieeeErrors}</syntaxhighlight>]] turns on IEEE error checking for floating-point constants.
*[[sNote/de|$NOTE]] creates a self-defined note
+
* [[$implicitExceptions|<syntaxhighlight lang="pascal" inline>{$implicitExceptions}</syntaxhighlight>]] controls insertion of implicit exceptions which aid prevention of memory leaks.
*[[sNotes/de|$NOTES]] enables the creation of self-defined notes
+
* [[$interfaces|<syntaxhighlight lang="pascal" inline>{$interfaces}</syntaxhighlight>]]
*[[sStop/de|$STOP]] display a self-defined fatal error message
+
* [[$IOChecks|<syntaxhighlight lang="pascal" inline>{$IOChecks}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$I}</syntaxhighlight>]] enables checks of input/output.
*[[sWarning/de|$WARNING]] creates a self-defined warning
+
* [[$objectChecks|<syntaxhighlight lang="pascal" inline>{$objectChecks}</syntaxhighlight>]] inserts code ensuring [[Self|<syntaxhighlight lang="pascal" inline>self</syntaxhighlight>]] is non-[[Nil|<syntaxhighlight lang="pascal" inline>nil</syntaxhighlight>]]
*[[sWarnings/de|$WARNINGS]] enables self-defined warnings.
+
* [[$optimization|<syntaxhighlight lang="pascal" inline>{$optimization}</syntaxhighlight>]] switches on certain optimizations.
 +
* [[$overflowChecks|<syntaxhighlight lang="pascal" inline>{$overflowChecks}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$Q}</syntaxhighlight>]] determines if overflow checks are inserted after arithmetic operations. In <syntaxhighlight lang="pascal" inline>{$mode MacPas}</syntaxhighlight> the directive <syntaxhighlight lang="pascal" inline>{$OV}</syntaxhighlight> is available, too.
 +
* [[$rangeChecks|<syntaxhighlight lang="pascal" inline>{$rangeChecks}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$R}</syntaxhighlight>]] determines insertion of code ensuring a value is within the permitted range.
 +
* [[$S|<syntaxhighlight lang="pascal" inline>{$S}</syntaxhighlight>]] creates code to check for stack overflows
 +
* [[$stackFrames|<syntaxhighlight lang="pascal" inline>{$stackFrames}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$W}</syntaxhighlight>]] determines conditions for the creation of stack frames.
  
''The following text is still to be translated to English:''
+
===$R versus $Q===
 +
There is the completely artificial distinction between the meaning of "overflow" and "range check" errors as defined by Borland. They are basically exactly the same error, except that one is detected by checking the overflow flag of the CPU and the other by explicitly comparing ranges.
  
==Lokale Compiler Direktiven nur für Intel 80x86 und kompatible Prozessoren==
+
On 64 bit CPUs, integer arithmetic is performed using 64 bit integers because of Pascal's convention to evaluate expressions using the native signed integer type. As a result, overflows cannot occur there when performing 32 bit arithmetic and you will get a range error instead when assigning the result to a 32 bit variable.
*[[sAsmmode/de|$ASMMODE]] Assemblermodus
+
Ideally, there would be only a single switch that governs both range/overflow checking, but because of historical reasons (as explained above) there are two.
*[[sI386xxx/de|$I386_XXX]] legt das Assemblerformat fest
 
*[[sMmx/de|$MMX]] erzwingt Optimierungen für den MMX Prozessor
 
*[[sSaturation/de|$SATURATION]] Saturation (Schutz gegen Speicherüberlauf) Operationen für den MMX Prozessor
 
*[[sMaxfpuregisters/de|$MAXFPUREGISTERS]] legt die maximale Anzahl der zu nutzenden Fliesskommaregister fest
 
  
==Lokale Compiler Direktiven nur für das Betriebssystem Darwin==
+
== Platform-specific ==
*[[sLinkframework/de|$LINKFRAMEWORK]] fügt ein Framework ein
+
=== For x86 processors only ===
 +
* [[$asmMode|<syntaxhighlight lang="pascal" inline>{$asmMode}</syntaxhighlight>]] determines the syntax the assembler reader expects. Previously, this has been the <syntaxhighlight lang="pascal" inline>{$i386…}</syntaxhighlight> directives.
 +
* [[$MMX|<syntaxhighlight lang="pascal" inline>{$MMX}</syntaxhighlight>]] enables optimizations for MMX processors.
 +
* [[$safeFPUExceptions|<syntaxhighlight lang="pascal" inline>{$safeFPUExceptions}</syntaxhighlight>]], whether <syntaxhighlight lang="asm" inline>fwait</syntaxhighlight> instructions are inserted
 +
* [[$saturation|<syntaxhighlight lang="pascal" inline>{$saturation}</syntaxhighlight>]] (in conjunction with <syntaxhighlight lang="pascal" inline>{$MMX}</syntaxhighlight>) enables saturation operations.
 +
* [[$maxFPUregisters|<syntaxhighlight lang="pascal" inline>{$maxFPUregisters}</syntaxhighlight>]] determines the maximum number of floating-points registers to use.
  
==Lokale Compiler Direktiven nur für Compiler Mode MacPas==
+
=== Other ===
Diese Befehle werden aus Kompatibilität zum existierenden Mac OS Pascal Compiler unterstützt:
+
* [[$linkFramework|<syntaxhighlight lang="pascal" inline>{$linkFramework}</syntaxhighlight>]] inserts a framework. This directive is only available on Darwin-based operating systems.
*[[sAlign/de|$A und $ALIGN]] bestimmt die Datenausrichtung von Records
 
*[[sErrorc/de|$ERRORC]] gibt eine Fehlermeldung aus
 
*[[sOv/de|$Q oder $OV]] überwacht den Überlauf von Integervariablen
 
==Bedingte Compilierung==
 
*[[sElsec/de|$ELSEC]] ist eine Verzweigung der bedingten Compilierung
 
*[[sElifc/de|$ELIFC]] ist eine Verzweigung der bedingten Compilierung
 
*[[sEndc/de|$ENDC]] ist das Ende einer bedingten Compilierung
 
*[[sIfc/de|$IFC]] ist der Anfang einer bedingten Compilierung
 
==Symbole==
 
*[[sDefinec/de|$DEFINEC]] erlaubt die Definition eigener Symbole
 
*[[sSetc/de|$SETC]] definiert ein Symbol und weist ihm einen Wert zu
 
*[[sUndefc/de|$UNDEFC]] hebt die Definition eines Symbols auf
 
  
 +
== Data inclusion ==
 +
* [[$link|<syntaxhighlight lang="pascal" inline>{$link}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$L}</syntaxhighlight>]] inserts an object file during linking.
 +
* [[$linkLib|<syntaxhighlight lang="pascal" inline>{$linkLib}</syntaxhighlight>]] inserts a library during linking.
 +
* [[$typeInfo|<syntaxhighlight lang="pascal" inline>{$typeInfo}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$M}</syntaxhighlight>]] creates [[Runtime Type Information (RTTI)|run-time type information]].
 +
* [[$resource|<syntaxhighlight lang="pascal" inline>{$resource}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$R}</syntaxhighlight>]] inserts a resource file.
  
[[Category: Compiler directives]]
+
== Compile-time context ==
 +
* [[$define|<syntaxhighlight lang="pascal" inline>{$define}</syntaxhighlight>]] defines a symbol. In <syntaxhighlight lang="pascal" inline>{$mode MacPas}</syntaxhighlight> the directive <syntaxhighlight lang="pascal" inline>{$defineC}</syntaxhighlight> is considered, too.
 +
* [[$include|<syntaxhighlight lang="pascal" inline>{$include}</syntaxhighlight> or <syntaxhighlight lang="pascal" inline>{$I}</syntaxhighlight>]] reads a file as source or includes certain compile-time/compiler information.
 +
* [[$push and $pop|<syntaxhighlight lang="pascal" inline>{$push}</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>{$pop}</syntaxhighlight>]] store and restore the compiler settings.
 +
* <syntaxhighlight lang="pascal" inline>{$setC}</syntaxhighlight> sets a compile-time variable, if the current mode allows it.
 +
* <syntaxhighlight lang="pascal" inline>{$undef}</syntaxhighlight> dismisses the definition of a previously defined symbol. In <syntaxhighlight lang="pascal" inline>{$mode MacPas}</syntaxhighlight> the directive <syntaxhighlight lang="pascal" inline>{$undefC}</syntaxhighlight> is recognized, too.
 +
 
 +
== Conditional compilation ==
 +
[[Conditional compilation]] can be achieved via the directives
 +
* <syntaxhighlight lang="pascal" inline>{$if}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$else}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$elseIf}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$endIf}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$ifDef}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$ifNDef}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$ifOpt}</syntaxhighlight>
 +
 
 +
Additionally, in <syntaxhighlight lang="pascal" inline>{$mode MacPas}</syntaxhighlight> the directives
 +
* <syntaxhighlight lang="pascal" inline>{$ifC}</syntaxhighlight>,
 +
* <syntaxhighlight lang="pascal" inline>{$elseC}</syntaxhighlight>,
 +
* <syntaxhighlight lang="pascal" inline>{$elIfC}</syntaxhighlight>, and
 +
* <syntaxhighlight lang="pascal" inline>{$endC}</syntaxhighlight>
 +
are allowed, too.
 +
 
 +
== Compile-time behavior ==
 +
With <syntaxhighlight lang="pascal" inline>{$wait}</syntaxhighlight>, the compiler waits till the user hits ↵ Enter, and then resumes compilation.
 +
 
 +
Self-defined messages can be triggered with the directives:
 +
* [[$message|<syntaxhighlight lang="pascal" inline>{$message}</syntaxhighlight>]], and the shortcuts
 +
** <syntaxhighlight lang="pascal" inline>{$stop}</syntaxhighlight>, which also aborts compilation
 +
** <syntaxhighlight lang="pascal" inline>{$fatal}</syntaxhighlight>, which also [[compile-time error|aborts compilation]]
 +
** <syntaxhighlight lang="pascal" inline>{$error}</syntaxhighlight> (in [[Mode MacPas|<syntaxhighlight lang="pascal" inline>{$mode MacPas}</syntaxhighlight>]] the directive <syntaxhighlight lang="pascal" inline>{$errorC}</syntaxhighlight> is accepted, too)
 +
** <syntaxhighlight lang="pascal" inline>{$warning}</syntaxhighlight>
 +
** <syntaxhighlight lang="pascal" inline>{$hint}</syntaxhighlight>
 +
** <syntaxhighlight lang="pascal" inline>{$note}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$info}</syntaxhighlight>
 +
 
 +
Emission of messages can be controlled via the directives:
 +
* [[$warn|<syntaxhighlight lang="pascal" inline>{$warn}</syntaxhighlight>]] for specific warnings, or
 +
* all messages of one kind in one go:
 +
** <syntaxhighlight lang="pascal" inline>{$warnings}</syntaxhighlight>
 +
** <syntaxhighlight lang="pascal" inline>{$hints}</syntaxhighlight>
 +
** <syntaxhighlight lang="pascal" inline>{$notes}</syntaxhighlight>
 +
 
 +
== Ignored ==
 +
Since [[FPC]] intends to be sort of compatible to some other compilers, some very common compiler directives stemming from the non-FPC-lands are recognized – not generating an illegal directive error – and ignored.
 +
Those are:
 +
* <syntaxhighlight lang="pascal" inline>{$F}</syntaxhighlight> (far or near functions)
 +
* <syntaxhighlight lang="pascal" inline>{$extendedSym}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$externalSym}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$hppEmit}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$libExport}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$noDefine}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$region}</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>{$endRegion}</syntaxhighlight>
 +
* <syntaxhighlight lang="pascal" inline>{$stringChecks}</syntaxhighlight> which in Delphi, this would control the generation of code that checks the sanity of string variables and arguments.
 +
 
 +
== Historical ==
 +
Following directives were recognized in earlier versions of FPC and are now illegal:
 +
* <syntaxhighlight lang="pascal" inline>{$output_format}</syntaxhighlight> determined the output format of an object file.
 +
 
 +
== See also ==
 +
* [[Pascal basics]]
 +
* [https://www.freepascal.org/docs-html/prog/progse2.html § “Local directives” in the ''Free Pascal programmer’s guide'']
 +
 
 +
{{Directives, Defines and Conditionals}}

Latest revision as of 16:14, 4 September 2021

Deutsch (de) English (en) français (fr)

Local compiler directives may be used more than once in a Pascal source code file.

Syntax

Data layout

Code generation

$R versus $Q

There is the completely artificial distinction between the meaning of "overflow" and "range check" errors as defined by Borland. They are basically exactly the same error, except that one is detected by checking the overflow flag of the CPU and the other by explicitly comparing ranges.

On 64 bit CPUs, integer arithmetic is performed using 64 bit integers because of Pascal's convention to evaluate expressions using the native signed integer type. As a result, overflows cannot occur there when performing 32 bit arithmetic and you will get a range error instead when assigning the result to a 32 bit variable. Ideally, there would be only a single switch that governs both range/overflow checking, but because of historical reasons (as explained above) there are two.

Platform-specific

For x86 processors only

  • {$asmMode} determines the syntax the assembler reader expects. Previously, this has been the {$i386…} directives.
  • {$MMX} enables optimizations for MMX processors.
  • {$safeFPUExceptions}, whether fwait instructions are inserted
  • {$saturation} (in conjunction with {$MMX}) enables saturation operations.
  • {$maxFPUregisters} determines the maximum number of floating-points registers to use.

Other

  • {$linkFramework} inserts a framework. This directive is only available on Darwin-based operating systems.

Data inclusion

Compile-time context

  • {$define} defines a symbol. In {$mode MacPas} the directive {$defineC} is considered, too.
  • {$include} or {$I} reads a file as source or includes certain compile-time/compiler information.
  • {$push} and {$pop} store and restore the compiler settings.
  • {$setC} sets a compile-time variable, if the current mode allows it.
  • {$undef} dismisses the definition of a previously defined symbol. In {$mode MacPas} the directive {$undefC} is recognized, too.

Conditional compilation

Conditional compilation can be achieved via the directives

  • {$if}
  • {$else}
  • {$elseIf}
  • {$endIf}
  • {$ifDef}
  • {$ifNDef}
  • {$ifOpt}

Additionally, in {$mode MacPas} the directives

  • {$ifC},
  • {$elseC},
  • {$elIfC}, and
  • {$endC}

are allowed, too.

Compile-time behavior

With {$wait}, the compiler waits till the user hits ↵ Enter, and then resumes compilation.

Self-defined messages can be triggered with the directives:

  • {$message}, and the shortcuts
    • {$stop}, which also aborts compilation
    • {$fatal}, which also aborts compilation
    • {$error} (in {$mode MacPas} the directive {$errorC} is accepted, too)
    • {$warning}
    • {$hint}
    • {$note}
  • {$info}

Emission of messages can be controlled via the directives:

  • {$warn} for specific warnings, or
  • all messages of one kind in one go:
    • {$warnings}
    • {$hints}
    • {$notes}

Ignored

Since FPC intends to be sort of compatible to some other compilers, some very common compiler directives stemming from the non-FPC-lands are recognized – not generating an illegal directive error – and ignored. Those are:

  • {$F} (far or near functions)
  • {$extendedSym}
  • {$externalSym}
  • {$hppEmit}
  • {$libExport}
  • {$noDefine}
  • {$region} and {$endRegion}
  • {$stringChecks} which in Delphi, this would control the generation of code that checks the sanity of string variables and arguments.

Historical

Following directives were recognized in earlier versions of FPC and are now illegal:

  • {$output_format} determined the output format of an object file.

See also

Directives, definitions and conditionals definitions
global compiler directives • local compiler directives

Conditional Compiler Options • Conditional compilation • Macros and Conditionals • Platform defines
$IF