Difference between revisions of "local compiler directives"

From Free Pascal wiki
(syntax: add since)
(correct until)
Line 10: Line 10:
 
* <syntaxhighlight lang="pascal" enclose="none">{$macro}</syntaxhighlight> enables usage of [[Macros|macros]].
 
* <syntaxhighlight lang="pascal" enclose="none">{$macro}</syntaxhighlight> enables usage of [[Macros|macros]].
 
* [[$scopedEnums|<syntaxhighlight lang="pascal" enclose="none">{$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]])
 
* [[$scopedEnums|<syntaxhighlight lang="pascal" enclose="none">{$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]])
* [[$static|<syntaxhighlight lang="pascal" enclose="none">{$static}</syntaxhighlight>]] enable usage of the reserved word <syntaxhighlight lang="delphi" enclose="none">static</syntaxhighlight> (until FPC 3.0.0).
+
* [[$static|<syntaxhighlight lang="pascal" enclose="none">{$static}</syntaxhighlight>]] enable usage of the reserved word <syntaxhighlight lang="delphi" enclose="none">static</syntaxhighlight> (until [[User Changes 2.6.0#The Static modifier is now always enabled|FPC 2.6.0]]).
 
* [[$typedAddress|<syntaxhighlight lang="pascal" enclose="none">{$typedAddress}</syntaxhighlight> or <syntaxhighlight lang="pascal" enclose="none">{$T}</syntaxhighlight>]] determines, if the address operator [[@|<syntaxhighlight lang="pascal" enclose="none">@</syntaxhighlight>]] results in a typed or untyped pointer.
 
* [[$typedAddress|<syntaxhighlight lang="pascal" enclose="none">{$typedAddress}</syntaxhighlight> or <syntaxhighlight lang="pascal" enclose="none">{$T}</syntaxhighlight>]] determines, if the address operator [[@|<syntaxhighlight lang="pascal" enclose="none">@</syntaxhighlight>]] results in a typed or untyped pointer.
 
* [[$varStringChecks|<syntaxhighlight lang="pascal" enclose="none">{$varStringChecks}</syntaxhighlight> and <syntaxhighlight lang="pascal" enclose="none">{$V}</syntaxhighlight>]] enables strict checking of assignment compatibility of string variables.
 
* [[$varStringChecks|<syntaxhighlight lang="pascal" enclose="none">{$varStringChecks}</syntaxhighlight> and <syntaxhighlight lang="pascal" enclose="none">{$V}</syntaxhighlight>]] enables strict checking of assignment compatibility of string variables.

Revision as of 21:08, 25 August 2019

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

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.

see also

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

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