Local directives
Local directives can occur more than once in a unit or program, If they have a command line counterpart, the command line argument is restored as the default for each compiled file. The local directives influence the compiler’s behavior from the moment they’re encountered until the moment another switch annihilates their behavior, or the end of the current unit or program is reached.
Note that the configuration file created by the installer can change some of the compiler differences mentioned here.
$A or $ALIGN : Align Data
The {$ALIGN} directive can be used to select the data alignment strategy of the compiler for records. It takes a numerical argument which can be 1, 2, 4, 8, 16 or 32, specifying the alignment boundary in bytes. For these values, it has the same effect as the {$PACKRECORDS} directive (see section Compiler directives).
Thus, the following
{$ALIGN 8}
is equivalent to
{$PACKRECORDS 8}
In MACPAS mode, additionally it can have the following values:
- MAC68K
-
Specifies alignment following the m68K ABI.
- POWER
-
Specifies alignment following the PowerPC ABI.
- POWERPC
-
Specifies alignment following the PowerPC ABI.
- RESET
-
Resets the default alignment.
- ON
-
Same as specifying 4.
- OFF
-
Same as specifying 1.
These values are not available in the {$PACKRECORDS} directive.
$A1, $A2,$A4 and $A8
These directives are the same as the $PACKRECORDS directive (see section Compiler directives), but they have the alignment specifier embedded in the directive. Thus the following:
{$A8 }
is equivalent to
{$PACKRECORDS 8}
Note that the special cases of $PACKRECORDS cannot be expressed this way.
$ASMMODE : Assembler mode (Intel 80x86 only)
The {$ASMMODE XXX} directive informs the compiler what kind of assembler it can expect in an asm block. The XXX should be replaced by one of the following:
- att
-
Indicates that
asmblocks contain AT&T syntax assembler. - intel
-
Indicates that
asmblocks contain Intel syntax assembler. - default
-
Tells the compiler to use the default assembler style as specified on the command-line, or, if it was not specified on the command-line, the default for the current platform. This can be used to reset the value to the default if it was changed.
These switches are local, and retain their value to the end of the unit that is compiled, unless they are replaced by another directive of the same type. The command line switch that corresponds to this switch is -R.
The default assembler reader is the AT&T reader.
$B or $BOOLEVAL : Complete boolean evaluation
By default, the compiler uses shortcut boolean evaluation, i.e., the evaluation of a boolean expression is stopped once the result of the total expression is known with certainty. The {$B } switch can be used to change this behavior: if its argument is +, then the compiler will always evaluate all terms in the expression. If it is - (the default) then the compiler will only evaluate as many terms as are necessary to determine the result of the complete expression.
So, in the following example, the function Bofu, which has a boolean result, will never get called.
If False and Bofu then ...
A consequence of this is that any additional actions that are done by Bofu are not executed. If compiled with {$B+}, then BoFu will be called anyway.
$C or $ASSERTIONS : Assertion support
The {$ASSERTIONS} switch determines if assert statements are compiled into the binary or not. If the switch is on, the statement
Assert(BooleanExpression,AssertMessage);
Will be compiled in the binary. If the BooleanExpression evaluates to False, the RTL will check if the AssertErrorProc is set. If it is set, it will be called with as parameters the AssertMessage message, the name of the file, the LineNumber and the address. If it is not set, a runtime error 227 is generated.
The AssertErrorProc is defined as
Type
TAssertErrorProc=procedure(Const msg,fname : String;
lineno,erroraddr : Longint);
Var
AssertErrorProc = TAssertErrorProc;
This can be used mainly for debugging purposes. The system unit sets the AssertErrorProc to a handler that displays a message on stderr and simply exits with a run-time error 227. The sysutils unit catches the run-time error 227 and raises an EAssertionFailed exception.
$BITPACKING : Enable bitsize packing
The $BITPACKING directive tells the compiler whether it should use bitpacking or not when it encounters the packed keyword for a structured type. The possible values are ON and OFF. If ON, then the compiler will bitpack structures when it encounters the Packed keyword.
In the following example, the TMyRecord record will be bitpacked:
{$BITPACKING ON}
Type
TMyRecord = packed record
B1,B2,B3,B4 : Boolean;
end;
Note that:
The
$BITPACKINGdirective is ignored in macpas mode, where packed records are always bitpacked.The
bitpackedkeyword can always be used to force bitwise packing, regardless of the value of the$BITPACKINGdirective, and regardless of the mode.
$CALLING : Specify calling convention
The {$CALLING } directive tells the compiler which calling convention should be used if none is specified:
{$CALLING REGISTER}
By default it is REGISTER. The following calling conventions exist:
- default
- register
- cdecl
- pascal
- safecall
- stdcall
- oldfpccall
For a more detailed explanation of calling conventions, see section Code issues. As a special case, DEFAULT can be used, to restore the default calling convention.
Remark: The calling convention of a procedural type is also changed by this directive.
$CHECKPOINTER : Check pointer values
The {$CHECKPOINTER} directive turns heap pointer checking on (value ON) or off (value OFF). If heap pointer checking is on and the code is compiled with the -gh (heaptrace) option on, then a check is inserted when dereferencing a pointer. The check will verify that the pointer contains a valid value, i.e. points to a location that is reachable by the program: the stack or a location in the heap. If not, a run-time error 216 or 204 is raised.
If the code is compiled without -gh switch, then this directive has no effect. Note that this considerably slows down the code.
Note that this only works for pointers managed by FPC. If you receive and use pointers from external libraries, the checks will fail.
$CODEALIGN : Set the code alignment
This switch sets the code alignment. It takes an argument which specifies the alignment for a particular kind of code generated by the compiler. The general form is
{$CODEALIGN PARAM=VALUE}
Where PARAM is the parameter to tune, and VAR value is a numerical value specifying an alignment. PARAM can be one of the following strings:
- PROC
-
Set the alignment for procedure entry points.
- JUMP
-
Set the alignment for jump destination locations.
- LOOP
-
Set alignment for loops (for, while, repeat).
- CONSTMIN
-
Minimum alignment for constants (both typed and untyped).
- CONSTMAX
-
Maximum alignment for constants (both typed and untyped).
- VARMIN
-
Minimum alignment for static and global variables.
- VARMAX
-
Maximum alignment for static and global variables.
- LOCALMIN
-
Minimum alignment for local variables.
- LOCALMAX
-
Maximum alignment for local variables.
- RECORDMIN
-
Minimum alignment for record fields.
- RECORDMAX
-
Maximum alignment for record fields.
By default the size of a data structure determines the alignment:
A
SmallIntwill be aligned at 2 bytes.A
LongIntwill be aligned at 4 bytes.A
Int64will be aligned at 8 bytes.
With the above switches the minimum required alignment and a maximum used alignment can be specified. The maximum allowed alignment is only meaningful if it is smaller than the natural size. i.e. setting the maximum alignment (e.g. VARMAX) to 4, the alignment is forced to be at most 4 bytes: The Int64 will then also be aligned at 4 bytes. The SmallInt will still be aligned at 2 bytes.
These values can also be specified on the command line as
-OaPARAM=VALUE
$COPERATORS : Allow C like operators
When the $COPERATORS directive or the -Si options are enabled, some assignments in the style of a C language available (disabled by default). They allow shorthand notation for some constructs:
var N: Double; begin N+=1; // same as N:=N+1 N-=2; // same as N:=N-2 N*=3; // same as N:=N*3 N/=4; // same as N:=N/4 end.
This form is no different from the regular one and generates the same code (and has the same requirements, for example, regarding the operand types).
Note that division is the Pascal / operator, not div, so it’s only available for float numbers. For integers, the full form (N := N div 5) must be explicitly used.
The expression to the right of the operator is evaluated first, then the operator itself. For example, the result of the following expression will be 6, not 4:
N:=3; N*=1+1; // same as N:=N*(1+1)
$DEFINE or $DEFINEC : Define a symbol
The directive
{$DEFINE name}
defines the symbol name. This symbol remains defined until the end of the current module (i.e. unit or program), or until a $UNDEF name directive is encountered.
If name is already defined, this has no effect. Name is case insensitive.
The symbols that are defined in a unit, are not saved in the unit file, so they are also not exported from a unit.
Under Mac Pascal mode, the $DEFINEC directive is equivalent to the $DEFINE directive and is provided for Mac Pascal compatibility.
{$DEFINE} can also be used to define macros or compile-time constants:
{$DEFINE cdecl:=stdcall}
will redefine the standard modifier cdecl as stdcall.
More information about macros and compile-time constants, can be found in section Using conditionals, messages and macros
The {$DEFINE} directive has a command-line equivalent, -d
-dNAME
will define the symbol Name. Using
-dcdecl:=stdcall
one can redefine the standard modifier cdecl as stdcall from the command-line.
$ELSE : Switch conditional compilation
The {$ELSE} switches between compiling and ignoring the source text delimited by the preceding {$IFxxx} and following {$ENDIF}. Any text after the ELSE keyword but before the brace is ignored:
{$ELSE some ignored text}
is the same as
{$ELSE}
This is useful for indication what switch is meant.
$ELSEC : Switch conditional compilation
In MACPAS mode, this directive can be used as an alternative to the $ELSE directive. It is supported for compatibility with existing macOSpascal compilers.
$ELSEIF or $ELIFC : Switch conditional compilation
This directive can be used as a shortcut for a new {$IF } directive inside an {$ELSE } clause:
{$IF XXX}
// XXX Code here
{$ELSEIF YYY}
// YYY code here
{$ELSE}
// And default code here
{$ENDIF}
is equivalent to
{$IF XXX}
// XXX Code here
{$ELSE }
{$IF YYY}
// YYY code here
{$ELSE}
// And default code here
{$ENDIF}
{$ENDIF}
The directive is followed by an expression like the ones recognized by the {$IF } directive.
The {$ELIFC } variant is allowed only in MACPAS mode.
$ENDC : End conditional compilation
In MACPAS mode, this directive can be used as an alternative to the $ENDIF directive. It is supported for compatibility with existing macOSpascal compilers.
$ENDIF : End conditional compilation
The {$ENDIF} directive ends the conditional compilation initiated by the last {$IFxxx} directive. Any text after the ENDIF keyword but before the closing brace is ignored:
{$ENDIF some ignored text}
is the same as
{$ENDIF}
This is useful for indication what switch is meant to be ended.
$ERROR or $ERRORC : Generate error message
The following code
{$ERROR This code is erroneous !}
will display an error message when the compiler encounters it, and increase the error count of the compiler. The compiler will continue to compile, but no code will be emitted.
The $ERRORC variant is supplied for Mac Pascal compatibility.
$ENDREGION: End of a collapsible region
This directive is parsed for Delphi compatibility but otherwise ignored. In Delphi, it marks the end of a collapsible region in the IDE.
$EXCESSPRECISION: use excess precision with float
This directive tells the compiler to use maximum precision when evaluating floating point expression, i.e. use the maximum possible precision, even if the members in the calculation have less than maximum precision. It accepts a boolean value (ON/OFF or +/-).
$EXTENDEDSYM: Ignored
This directive is parsed for Delphi compatibility but otherwise ignored. A warning will be displayed when this directive is encountered.
$EXTERNALSYM: Ignored
This directive is parsed for Delphi compatibility but otherwise ignored.
$F : Far or near functions
This directive is recognized for compatibility with Turbo Pascal. Under the 32-bit and 64-bit programming models, the concept of near and far calls have no meaning, hence the directive is ignored. A warning is printed to the screen, as a reminder.
As an example, the following piece of code:
{$F+}
Procedure TestProc;
begin
Writeln ('Hello From TestProc');
end;
begin
testProc
end.
Generates the following compiler output:
malpertuus: >pp -vw testf Compiler: ppc386 Units are searched in: /home/michael;/usr/bin/;/usr/lib/ppc/0.9.1/linuxunits Target OS: Linux Compiling testf.pp testf.pp(1) Warning: illegal compiler switch 7739 kB free Calling assembler... Assembled... Calling linker... 12 lines compiled, 1.00000000000000E+0000
One can see that the verbosity level was set to display warnings.
When declaring a function as Far (this has the same effect as setting it between {$F+} …{$F-} directives), the compiler also generates a warning:
testf.pp(3) Warning: FAR ignored
The same story is true for procedures declared as Near. The warning displayed in that case is:
testf.pp(3) Warning: NEAR ignored
$FATAL : Generate fatal error message
The following code
{$FATAL This code is erroneous !}
will display an error message when the compiler encounters it, and the compiler will immediately stop the compilation process.
This is mainly useful in conjunction with {$IFDEF} or {$IFOPT} statements.
$FPUTYPE : Select coprocessor type
This directive selects the type of coprocessor used to do floating point calculations. The directive must be followed by the type of floating point unit. The allowed values depend on the target CPU:
- all
-
SOFT: FPC emulates the coprocessor (not yet implemented). - i386
-
X87,SSE,SSE2: code compiled withSSEuses the sse to do calculations involving a float of typeSingle. This code runs only on Pentium III and above, or AthlonXP and above. Code compiled withSSE2uses thesseunit to do calculations with the single and double data type. This code runs only on PentiumIV and above or Athlon64 and above - x86-64
-
SSE64 - powerpc
-
STANDARD - arm
-
LIBGCC,FPA,FPA10,FPA11,VFP.
This directive corresponds to the -Cf command line option.
$GOTO : Support Goto and Label
If {$GOTO ON} is specified, the compiler will support Goto statements and Label declarations. By default, $GOTO OFF is assumed. This directive corresponds to the -Sg command line option.
As an example, the following code can be compiled:
{$GOTO ON}
label Theend;
begin
If ParamCount=0 then
GoTo TheEnd;
Writeln ('You specified command line options');
TheEnd:
end.
Remark: When compiling assembler code using the inline assembler readers, any labels used in the assembler code must be declared, and the {$GOTO ON} directive should be used.
$H or $LONGSTRINGS : Use AnsiStrings
If {$LONGSTRINGS ON} is specified, the keyword String (no length specifier) will be treated as AnsiString, and the compiler will treat the corresponding variable as an ansistring, and will generate corresponding code. This switch corresponds to the -Sh command line option.
By default, the use of ansistrings is off, corresponding to {$H-}. The system unit is compiled without ansistrings, all its functions accept shortstring arguments. The same is true for all RTL units, except the sysutils unit, which is compiled with ansistrings.
However, the {$MODE} statement influences the default value of {$H}: a {$MODE DELPHI} directive implies a {$H+} statement, all other modes switch it off. As a result, you should always put {$H+} after a mode directive. This behavior has changed, in older Free Pascalversions this was not so.
$HINT : Generate hint message
If the generation of hints is turned on, through the -vh command line option or the {$HINTS ON} directive, then
{$Hint This code should be optimized }
will display a hint message when the compiler encounters it.
By default, no hints are generated.
$HINTS : Emit hints
{$HINTS ON} switches the generation of hints on. {$HINTS OFF} switches the generation of hints off. Contrary to the command line option -vh this is a local switch, this is useful for checking parts of the code.
$HPPEMIT: Ignored
This directive is parsed for Delphi compatibility but otherwise ignored.
$IF : Start conditional compilation
The directive {$IF expr} will continue the compilation if the boolean expression expr evaluates to True. If the compilation evaluates to False, then the source is skipped to the first {$ELSE} or {$ENDIF} directive.
The compiler must be able to evaluate the expression at parse time. This means that variables or constants that are defined in the source cannot be used. Macros and symbols may be used, however.
More information on this can be found in the section about conditionals, Using conditionals, messages and macros on page .
Note that the compiler will only consider valid expressions. As soon as something invalid in the expression is encountered, the rest is considered comment. In the following, both conditions are checked:
{$if defined(define1) or defined(define2)}
But in the below, only define1 is checked, the rest is considered a comment:
{$if defined(define1) defined(define2)}
$IFC : Start conditional compilation
In MACPAS mode, this directive can be used as an alternative to the $IF directive. It is supported for compatibility with existing macOSpascal compilers.
$IFDEF Name : Start conditional compilation
If the symbol Name is not defined then the {$IFDEF name} will skip the compilation of the text that follows it to the first {$ELSE} or {$ENDIF} directive. If Name is defined, then compilation continues as if the directive wasn’t there.
The $IFDEF directive will only check the first word of what follows, all the rest is ignored. This means that code after a
{$IFDEF RED}
and
{$IFDEF RED check that red is defined}
and
{$IFDEF RED or Blue}
will only be parsed if RED is defined. The other words are ignored. In particular, the existence of BLUE will not be checked for the last case. If you need to check multiple values, you should use the {$IF} construct instead.
$IFEND : End conditional compilation
This directive can be used as an alternative to the $ENDIF directive.
$IFNDEF : Start conditional compilation
If the symbol Name is defined then the {$IFNDEF name} will skip the compilation of the text that follows it to the first {$ELSE} or {$ENDIF} directive. If it is not defined, then compilation continues as if the directive wasn’t there.
Similar to $IFDEF, the $IFNDEF directive will only check the first word of what follows, all the rest is ignored. This means that code after a
{$IFNDEF RED}
and
{$IFNDEF RED check that red is defined}
and
{$IFNDEF RED or Blue}
will only be parsed if RED is undefined. The other words are ignored. In particular, the existence of BLUE will not be checked for the last case. If you need to check multiple values, you should use the {$IF} construct instead.
$IFOPT : Start conditional compilation
The {$IFOPT switch} will compile the text that follows it if the switch switch is currently in the specified state. If it isn’t in the specified state, then compilation continues after the corresponding {$ELSE} or {$ENDIF} directive.
As an example:
{$IFOPT M+}
Writeln ('Compiled with type information');
{$ENDIF}
Will compile the Writeln statement only if generation of type information is on.
Remark: The {$IFOPT} directive accepts only short options, i.e. {$IFOPT TYPEINFO} will not be accepted.
$IMPLICITEXCEPTIONS : Implicit finalization code generation
The compiler generates an implicit try...finally frame around each procedure that needs initialization or finalization of variables, and finalizes the variables in the finally block. This slows down these procedures (up to 5-10% sometimes). With this directive, the generation of such frames can be disabled. One should be careful with this directive, because it can lead to memory leaks if an exception occurs inside the routine. Therefore, it is set to ON by default.
$INFO : Generate info message
If the generation of info is turned on, through the -vi command line option, then
{$INFO This was coded on a rainy day by Bugs Bunny}
will display an info message when the compiler encounters it.
This is useful in conjunction with the {$IFDEF} directive, to show information about which part of the code is being compiled.
$INLINE : Allow inline code.
The {$INLINE ON} directive tells the compiler that the Inline procedure modifier should be allowed. Procedures that are declared inline are copied to the locations where they are called. This has the effect that there is no actual procedure call, the code of the procedure is just copied to where the procedure is needed, this results in faster execution speed if the function or procedure is used a lot.
By default, Inline procedures are not allowed. This directive must be specified to use inlined code. The directive is equivalent to the command line switch -Si. For more information on inline routines, consult the Language Reference.
$INTERFACES : Specify Interface type.
The {$INTERFACES} directive tells the compiler what it should take as the parent interface of an interface declaration which does not explicitly specify a parent interface. By default the Windows COM IUnknown interface is used. Other implementations of interfaces (CORBA or Java) do not necessarily have this interface, and for such cases, this directive can be used. It accepts the following three values:
- COM
-
Interfaces will descend from
IUnknownand will be reference counted. - CORBA
-
Interfaces will not have a parent and are not reference counted (so the programmer is responsible for bookkeeping). Corba interfaces are identified by a simple string so they are assignment compatible with strings and not
TGUID. - DEFAULT
-
Currently, this is COM.
$I or $IOCHECKS : Input/Output checking
The {$I-} or {$IOCHECKS OFF} directive tells the compiler not to generate input/output checking code in the program. By default, the compiler generates I/O checking code. This behavior can be controlled globally with the -Ci switch.
When compiling using the -Ci compiler switch, the Free Pascalcompiler inserts input/output checking code after every input/output call in the code. If an error occurred during input or output, then a run-time error will be generated. This switch can also be used to avoid this behavior.
If no I/O checking code is generated, to check if something went wrong, the IOResult function can be used to see if everything went without problems.
Conversely, {$I+} will turn error-checking back on, until another directive is encountered which turns it off again.
Remark: When an I/O error occurs and I/O-checking code generation is off, all subsequent I/O operations are ignored until the IO error status code is cleared.
When the IOResult function from the system unit is called, it returns the current IO status code and resets it.
The effect of this is that IOResult must be checked after each I/O operation for subsequent I/O operations to succeed.
The most common use for this switch is to check if the opening of a file went without problems, as in the following piece of code:
assign (f,'file.txt');
{$I-}
rewrite (f);
{$I+}
if IOResult<>0 then
begin
Writeln ('Error opening file: "file.txt"');
exit
end;
See the IOResult function explanation in Language Referencefor a detailed description of the possible errors that can occur when using input/output checking.
$IEEEERRORS : Enable IEEE error checking for constants
This boolean directive switches IEEE (floating point) error checking for constants on or off. It is the local equivalent of the global -C3 command-line switch.
The following turns on IEEE (floating point) error checking for constants:
{$IEEEERRORS ON}
$I or $INCLUDE : Include file
The {$I filename} or {$INCLUDE filename} directive tells the compiler to read further statements from the file filename. The statements read there will be inserted as if they occurred in the current file.
If the file with the given filename exists, it will be included. If no extension is given, the compiler will append the .pp extension to the file and try with that filename. No other extensions are tried.
The filename can be placed between single quotes, they will not be regarded as part of the file’s name. Indeed, if the filename contains a space, then it must be surrounded by single quotes:
{$I 'my file name'}
will try to include the file my file name or my file name.pp.
{$I my file name}
will try to include the file my or my.pp.
If the filename is an asterisk (*) then the compiler will use the unit or program name as filename and try to include that. The following code
unit testi;
interface
{$I *}
implementation
end.
will include the file testi or testi.pp if they exist.
Care should be taken with this mechanism, because the unit name should already match the unit filename, meaning most likely the unit will include itself recursively.
Include files can be nested, but not infinitely deep. The number of files is restricted to the number of file descriptors available to the Free Pascalcompiler.
Contrary to Turbo Pascal, include files can cross blocks. I.e. a block can start in one file (with a Begin keyword) and can end in another (with a End keyword). The smallest entity in an include file must be a token, i.e. an identifier, keyword or operator.
The compiler will look for the file to include in the following locations:
It will look in the path specified in the include file name.
It will look in the directory where the current source file is.
it will look in all directories specified in the include file search path.
Directories can be added to the include file search path with the -Fi command line option.
$I or $INCLUDE : Include compiler info
In this form:
{$INCLUDE %XXX%}
the {$INCLUDE} directive inserts a string constant in the source code.
Here XXX can be one of the following:
- CURRENTROUTINE
-
Inserts the name of the current routine. Useful for debug logging.
- DATE
-
Inserts the current date. It will be formatted as YYYY/MM/DD.
- DATEYEAR
-
Inserts the year part of the current date.
- DATEMONTH
-
Inserts the month part of the current date.
- DATEDAY
-
Inserts the day part of the current date.
- FPCTARGET
-
Inserts the target CPU name. (deprecated, use
FPCTARGETCPU) - FPCTARGETCPU
-
Inserts the target CPU name.
- FPCTARGETOS
-
Inserts the target OS name.
- FPCVERSION
-
Current compiler version number.
- FILE
-
Filename in which the directive is found.
- LINE
-
Line number on which the directive is found.
- LINENUM
-
Line number on which the directive is found. In this case, the result is an integer, not a string.
- TIME
-
Current time, formatted as HH:MM:SS.
- TIMEHOUR
-
Hour part of the current time.
- TIMEMINUTE
-
Minutes part of the current time.
- TIMESECOND
-
Seconds part of the current time.
If XXX is none of the above, then it is assumed to be the name of an environment variable. Its value will be fetched from the environment, if it exists, otherwise an empty string is inserted. As a result, this will generate a macro with the value of the XXX specifier, as if it were a string (or, in the case of LINENUM, an integer).
Remark: Note that the time arguments are the times when the directive is processed. Thus it is possible that different time stamps appear in the strings even if they are in the same unit but on different locations in the file.
For example, the following program
Program InfoDemo;
Const User = {$I %USER%};
begin
Write ('This program was compiled at ',{$I %TIME%});
Writeln (' on ',{$I %DATE%});
Writeln ('By ',User);
Writeln ('Compiler version: ',{$I %FPCVERSION%});
Writeln ('Target CPU: ',{$I %FPCTARGET%});
end.
Creates the following output:
This program was compiled at 17:40:18 on 1998/09/09 By michael Compiler version: 0.99.7 Target CPU: i386
Remark: Note that the inclusion of DATE and TIME will not cause the compiler to recompile the unit every time it is used: the date and time will be the date and time when the unit was last compiled. Therefore, the most reliable place to put this directive is the program’s main file. Otherwise, a clean build will have to be used.
$J or $WRITEABLECONST : Allow assignments to typed consts
This boolean switch tells the compiler whether or not assignments to typed constants are allowed. The default is to allow assignments to typed constants.
The following statement will switch off assignments to typed constants:
{$WRITEABLECONST OFF}
After this switch, the following statement will no longer compile:
Const MyString : String = 'Some nice string'; begin MyString:='Some Other string'; end.
But an initialized variable will still compile:
Var MyString : String = 'Some nice string'; begin MyString:='Some Other string'; end.
$L or $LINK : Link object file
The {$L filename} or {$LINK filename} directive tells the compiler that the file filename should be linked to the program. This cannot be used for libraries, see section Compiler directives for that.
The compiler will look for this file in the following locations:
In the path specified in the object file name.
In the directory where the current source file is.
In all directories specified in the object file search path.
Directories can be added to the object file search path with the -Fo command line option.
On Linuxsystems and on operating systems with case-sensitive file systems (such as Unixsystems), the name is case sensitive, and must be typed exactly as it appears on your system.
Remark: Take care that the object file you’re linking is in a format the linker understands. Which format this is, depends on the platform you’re on. Typing ld or ld --help on the command line gives a list of formats ld knows about.
Other files and options can be passed to the linker using the -k command line option. More than one of these options can be used, and they will be passed to the linker, in the order that they were specified on the command line, just before the names of the object files that must be linked.
$LIBEXPORT : Ignored
This directive is recognized for Darwin pascal compilers, but is otherwise ignored.
$LINKFRAMEWORK : Link to a framework
The {$LINKFRAMEWORK name} will link to a framework named name. This switch is available only on the Darwin platform.
$LINKLIB : Link to a library
The {$LINKLIB name} will link to a library name. This has the effect of passing -lname to the linker.
As an example, consider the following unit:
unit getlen;
interface
{$LINKLIB c}
function strlen (P : pchar) : longint;cdecl;
implementation
function strlen (P : pchar) : longint;cdecl;external;
end.
If one would issue the command
ppc386 foo.pp
where foo.pp has the above unit in its uses clause, then the compiler would link the program to the c library, by passing the linker the -lc option.
The same can be obtained by removing the linklib directive in the above unit, and specify -k-lc on the command line:
ppc386 -k-lc foo.pp
Note that the linker will look for the library in the linker library search path: one should never specify a complete path to the library. The linker library search path can be set with the -Fl command line option.
Remark: The compiler internally uses library names libimp*.*; as a side effect, you cannot use the LINKLIB statement to link to a library with such a name.
$M or $TYPEINFO : Generate type info
For classes that are compiled in the {$M+} or {$TYPEINFO ON} state, the compiler will generate Run-Time Type Information (RTTI). All descendent class of a class that was compiled in the {$M+} state will get RTTI information too. Any class that is used as a field or property in a published section will also get RTTI information.
By default, no Run-Time Type Information is generated for published sections, making them equivalent to public sections. Only when a class (or one of its parent classes) was compiled in the {$M+} state, the compiler will generate RTTI for the methods and properties in the published section.
The TPersistent object that is present in the classes unit (part of the RTL) is generated in the {$M+} state. The generation of RTTI allows programmers to stream objects, and to access published properties of objects, without knowing the actual class of the object.
The run-time type information is accessible through the TypInfo unit, which is part of the Free PascalRun-Time Library.
Remark: The streaming system implemented by Free Pascalrequires that all streamable components be descendants from TPersistent. It is possible to create classes with published sections that do not descend from TPersistent, but those classes will not be streamed correctly by the streaming system of the Classes unit.
Note that this directive has the same abbreviation as the global $MEMORY directive: $M (section Compiler directives).
$MACRO : Allow use of macros.
In the {$MACRO ON} state, the compiler allows the use of C-style (although not as elaborate) macros. Macros provide a means for simple text substitution. This directive is equivalent to the command line option -Sm. By default, macros are not allowed.
More information on using macros can be found in section Using conditionals, messages and macros.
$MAXFPUREGISTERS : Maximum number of FPU registers for variables
The {$MAXFPUREGISTERS XXX} directive tells the compiler how many floating point variables can be kept in the floating point processor registers on an Intel X86 processor. This switch is ignored unless the -Or (use register variables) optimization is used.
This is quite tricky because the Intel FPU stack is limited to 8 entries. The compiler uses a heuristic algorithm to determine how many variables should be put onto the stack: in leaf procedures it is limited to 3 and in non leaf procedures to 1. But in case of a deep call tree or, even worse, a recursive procedure, this can still lead to a FPU stack overflow, so the user can tell the compiler how many (floating point) variables should be kept in registers.
The directive accepts the following arguments:
- N
-
where
Nis the maximum number of FPU registers to use. Currently this can be in the range 0 to 7. - Normal
-
Restores the heuristic and standard behavior.
- Default
-
Restores the heuristic and standard behavior.
Remark: This directive is valid until the end of the current procedure.
$MESSAGE : Generate user-defined message
The $MESSAGE directive allows to insert user-defined Warning, Hint or Note. It is equivalent to one of the $FATAL, $ERROR, $WARNING, $HINT or $NOTE directives. It must be followed by one of the words ERROR WARNING HINT or NOTE, and then the message to display, as follows:
{$MESSAGE WARNING This was coded on a rainy day by Bugs Bunny}
This will display a warning message when the compiler encounters it. The effect is the same as the {$WARNING} directive.
This means that the following:
{$MESSAGE WARNING Coded on a rainy day}
{$MESSAGE NOTE Coded on a very very rainy day}
{$MESSAGE HINT Coded on a very rainy day}
{$MESSAGE ERROR This is wrong}
{$MESSAGE FATAL This is so wrong, the compiler will stop at once}
is completely equivalent to
{$WARNING Coded on a rainy day}
{$NOTE Coded on a very very rainy day}
{$HINT Coded on a very rainy day}
{$ERROR This is wrong}
{$FATAL This is so wrong, the compiler will stop at once}
Note that if the -Sew switch is used, the WARNING message will be treated as an error, and the compiler will stop.
$MINENUMSIZE : Specify minimum enumeration size
This directive is provided for Delphi compatibility: it has the same effect as the $PACKENUM directive (see section Compiler directives).
$MINFPCONSTPREC : Specify floating point constant precision
This switch is the equivalent of the -CF command line switch. Normally, the compiler will set the precision of a floating point constant to the minimally required precision to represent it exactly.
This switch can be used to ensure that the compiler never lowers the precision below the specified value. Supported values are 32, 64 and DEFAULT. 80 is not supported for implementation reasons.
Note that this has nothing to do with the actual precision used by calculations: there the type of the variable will determine what precision is used. This switch determines only with what precision a constant declaration is stored:
{$MINFPCONSTPREC 64}
Const
MyFloat = 0.5;
The type of the above constant will be double even though it can be represented exactly using single.
Note that a value of 80 (Extended precision) is not supported.
$MMX : Intel MMX support (Intel 80x86 only)
Free Pascalsupports optimization for the MMX Intel processor (see also chapter Intel MMX support).
This optimizes certain code parts for the MMX Intel processor, thus greatly improving speed. The speed is noticed mostly when moving large amounts of data. Things that change are
Data with a size that is a multiple of 8 bytes is moved using the
movqassembler instruction, which moves 8 bytes at a time
Remark: MMX support is NOT emulated on non-MMX systems, i.e. if the processor doesn’t have the MMX extensions, the MMX optimizations cannot be used.
When MMX support is on, it is not allowed to do floating point arithmetic. It is allowed to move floating point data, but no arithmetic can be done. If floating point math must be done anyway, first MMX support must be switched off and the FPU must be cleared using the emms function of the cpu unit.
The following example will make this more clear:
Program MMXDemo;
uses mmx;
var
d1 : double;
a : array[0..10000] of double;
i : longint;
begin
d1:=1.0;
{$mmx+}
{ floating point data is used, but we do _no_ arithmetic }
for i:=0 to 10000 do
a[i]:=d2; { this is done with 64 bit moves }
{$mmx-}
emms; { clear fpu }
{ now we can do floating point arithmetic }
...
end.
See the chapter on MMX (Intel MMX support) for more information on this topic.
$NODEFINE : Ignored
This directive is parsed for Delphi compatibility but is otherwise ignored. Not to be confused with the $UNDEF directive.
$NOTE : Generate note message
If the generation of notes is turned on, through the -vn command line option or the {$NOTES ON} directive, then
{$NOTE Ask Santa Claus to look at this code}
will display a note message when the compiler encounters it.
$NOTES : Emit notes
{$NOTES ON} switches the generation of notes on. {$NOTES OFF} switches the generation of notes off. Contrary to the command line option -vn this is a local switch, this is useful for checking parts of the code.
By default, {$NOTES} is off.
$OBJECTCHECKS : Check Object
This boolean switch determines whether code to test the SELF pointer is inserted in methods. By default it is OFF. For example:
{$OBJECTCHECKS ON}
If the SELF pointer is NIL a run-time error 210 (range check) will be generated. In case of typecasts, an implicit type check will be generated in the ON state, the type check will be omitted in the OFF state.
This switch is also activated by the -CR command line option, so you can undo the effects of -CR on objects with
{$OBJECTCHECKS OFF}
$OPTIMIZATION : Enable Optimizations
This switch enables optimization. It can have the following possible values:
- ON
-
Switches on optimizations, corresponding to level 2 optimizations.
- OFF
-
Switches off all kinds of optimizations.
- DEFAULT
-
Returns to default (i.e. command-line or config file) specified optimizations.
- XYZ
-
Parses the string and switches on the optimizations found in the string as if they were passed using the
-Oocommand line option. The optimizations must be separated by commas.
The following strings are supported:
- REGVAR
-
Use register variables.
- UNCERTAIN
-
Use uncertain optimizations.
- SIZE
-
Optimize for size.
- STACKFRAME
-
Skip stackframes.
- PEEPHOLE
-
Peephole optimizations.
- ASMCSE
-
Use common subexpression elimination at the assembler level.
- LOOPUNROLL
-
Unroll loops.
- TAILREC
-
Change tail recursion to regular while.
- ORDERFIELDS
-
Reorder fields if this results in better alignment.
- FASTMATH
-
Fast math operations.
- REMOVEEMPTYPROCS
-
Remove calls to empty procedures.
- CSE
-
Use common subexpression elimination.
- DFA
-
Use DFA (Data Flow Analysis).
- STRENGTH
-
Only used when DFA is also specified: try to replace a loop over an array index with a pointer that runs over the elements.
- AUTOINLINE
-
Try to automatically inline procedures where appropriate.
- LEVEL1
-
Enable some level 1 optimizations, dependent on the CPU. Note that this is not the same as
-O1, it is a separate flag. - LEVEL2
-
Enable some level 2 optimizations, dependent on the CPU. Note that this is not the same as
-O2, it is a separate flag. - LEVEL3
-
Enable some level 3 optimizations, dependent on the CPU. Note that this is not the same as
-O3, it is a separate flag. - LEVEL4
-
Enable some level 4 optimizations, dependent on the CPU. Note that this is not the same as
-O4, it is a separate flag. - SCHEDULE
-
ARM CPU only: perform instruction scheduling. Enabled by default at -O3 and higher.
- USEEBP
-
i8086 and i386 CPUs only: use the (E)BP register for register variables when it is not used to hold the frame pointer. Enabled by default when using level 4 optimizations.
- USERBP
-
x86-64 CPU only: use the RBP register for register variables when it is not used to hold the frame pointer. Enabled by default when using level 4 optimizations.
- DEADVALUES
-
Allow removing expressions whose result is not used, even when this can change program behaviour. For example, range check errors can disappear when indexing an array and not doing anything with the loaded value, or access violations due to invalid pointer dereferences can disappear.
Note: it does not (and must not) remove expressions that have explicit side-effects. Enabled by default when using level 4 optimizations. - CONSTPROP
-
Perform constant propagation across statements. Enabled by default when using level 3 optimizations or higher.
- DEADSTORE
-
Remove stores to variables if the value of that variable is no longer used afterwards. This optimization is not enabled by default at any optimization level. Requires DFA (Data Flow Analysis) to be active (otherwise it won’t do anything), which itself is enabled by default when using level 3 optimizations or higher.
- FORCENOSTACKFRAME
-
ARM and Xtensa CPU only (currently the switch is not yet used there). Do not use a separate frame pointer register if a procedure/function has no nested pure assembler procedures/functions. This requires the compiler to estimate the size of the stack frame in advance, and if that estimate is wrong this will result in an internal compiler error. For this reason it is not enabled by default at any optimization level.
- USELOADMODIFYSTORE
-
Optimize expressions of the form "x := x <op> y" by directly modifying the value of x rather than loading, modifying and then storing it. This is not enabled by default at any optimization level.
You can disable a certain optimization by prefixing the value with NO.
Example:
{$OPTIMIZATION ON}
is equivalent to
{$OPTIMIZATION LEVEL2}
Multiple optimizations can be specified with:
{$OPTIMIZATION REGVAR,SIZE,LEVEL2}
Disable loop unrolling with:
{$OPTIMIZATION NOLOOPUNROLL}
This switch is also activated by the -Ooxxx command line switch. Note the small ’o’: it is -Oo followed by the switch name.
Note that the optimizations are not saved/restored by the $PUSH and $POP directives.
$PACKENUM or $Z : Minimum enumeration type size
This directive tells the compiler the minimum number of bytes it should use when storing enumerated types. It is of the following form:
{$PACKENUM xxx}
{$MINENUMSIZE xxx}
Where the form with $MINENUMSIZE is for Delphi compatibility. xxx can be one of 1,2 or 4, or NORMAL or DEFAULT (or 0).
The default enumeration size depends on the compiler mode:
In Delphi and TP mode, the size is 1.
In MacPas mode, the size is 2.
In all other modes, the default is 4.
As an alternative form one can use {$Z1}, {$Z2} {$Z4}. The {$Z} form takes a +/- argument, where + is equivalent to {$Z4} and - is equivalent to {$Z1}.
So the following code
{$PACKENUM 1}
Type
Days = (monday, tuesday, wednesday, thursday, friday,
saturday, sunday);
will use 1 byte to store a variable of type Days, whereas it normally would use 4 bytes. The above code is equivalent to
{$Z1}
Type
Days = (monday, tuesday, wednesday, thursday, friday,
saturday, sunday);
or equivalent to
{$Z-}
Type
Days = (monday, tuesday, wednesday, thursday, friday,
saturday, sunday);
It is important to note that the number of elements is determined by the highest value of the enumeration. If the enumeration has assigned values, then the "number of elements" is actually the highest value in the enumeration+1.
program Project1;
{$PACKENUM 2}
type
TEnum = (a, b, c = $FFFF + 1);
begin
writeln(sizeof(TEnum)); // 4
end.
will print 4 because the number of elements is $FFFF+2
$PACKRECORDS : Alignment of record elements
This directive controls the byte alignment of the elements in a record, object or class type definition.
It is of the following form:
{$PACKRECORDS n}
Where n is one of 1, 2, 4, 8, 16, 32, C, NORMAL or DEFAULT (or 0).
This means that the elements of a record which have an ABI alignment greater than n will be aligned on n byte boundaries. Elements with size less than or equal to n will be aligned to the ABI alignment for the platform. The special value C is used to specify alignment as by the platform’s C compiler. It must be used when making import units for C structured.
The default alignment (which can be selected with DEFAULT) is the ABI alignment.
More information on this and an example program can be found in the Language Reference, in the section about record types.
The following shorthands can be used for this directive:
{$A1 }
{$A2 }
{$A4 }
{$A8 }
$PACKSET : Specify set size
The $PACKSET directive takes a numeric argument of 1, 2, 4 or 8. This number determines the number of bytes used to store a set: The compiler rounds the number of bytes needed to store the set down/up to the closest multiple of the PACKSET setting, with the exception that 3-byte sets are always rounded up to 4-byte sets.
Other allowed values are FIXED, DEFAULT (or 0), or NORMAL. With these values, the compiler stores sets with less than 32 elements in 4 bytes, and sets with less than 256 elements in 32 bytes.
$POP : Restore compiler settings
The $POP directive restores the values of all local compiler switches (so not all directives) with the last values that were stored on the settings stack. The settings are then deleted from the stack.
The settings can be stored on the stack with the $PUSH directive (see section Compiler directives).
Note that global settings are not restored by this directive.
$PUSH : Save compiler settings
The $PUSH directive saves the current values of all local compiler switches except optimization settings on the settings stack. Up to 20 sets of settings can be stored on the stack.
Some verbosity directives ($Warn etc.) as well as the $PACKENUM, $PACKRECORDS and $SETALLOC are also saved.
The settings can be restored from the stack using the $POP directive (see section Compiler directives).
Note that global settings (search paths etc.) are not saved by this directive.
The settings stack is preserved across units, i.e. when the compiler starts compiling a new unit, the stack is not emptied.
$Q or $OV or $OVERFLOWCHECKS: Overflow checking
The {$Q+} or {$OV+} (MACPAS mode only) or {$OVERFLOWCHECKS ON} directive turns on integer overflow checking. This means that the compiler inserts code to check for overflow when doing computations with integers. When an overflow occurs, the run-time library will generate a run-time error 215: it prints a message Overflow at xxx, and exits the program with exit code 215.
Remark: Overflow checking behavior is not the same as in Turbo Pascal since all arithmetic operations are done via 32-bit or 64-bit values. Furthermore, the Inc() and Dec() standard system procedures are checked for overflow in Free Pascal, while in Turbo Pascal they are not.
Using the {$Q-} switch (or the {$OV-} switch in MACPAS mode) switches off the overflow checking code generation.
The generation of overflow checking code can also be controlled using the -Co command line compiler option (see the User’s Guide).
In Delphi, overflow checking is only switchable at the procedure level. In Free Pascal, the {$Q} directive can be used at the expression level.
Remark: Overflow checking and range checking (see the next section) are basically 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 by convention in Pascal expressions are evaluated using the native signed integer type, on 64 bit cpus integer arithmetic are performed using 64 bit integers.
As a result, overflows cannot occur there when performing 32 bit arithmetic, instead a range error will occur when assigning the result to a 32 bit variable.
$R or $RANGECHECKS : Range checking
By default, the compiler doesn’t generate code to check the ranges of array indices, enumeration types, subrange types, etc. Specifying the {$R+} switch tells the computer to generate code to check these indices. If, at run-time, an index or enumeration type is specified that is out of the declared range of the compiler, then a run-time error is generated, and the program exits with exit code 201. This can happen when doing a typecast (implicit or explicit) on an enumeration type or subrange type.
The {$RANGECHECKS OFF} switch tells the compiler not to generate range checking code. This may result in faulty program behavior, but no run-time errors will be generated.
Remark: The standard functions val and Read will also check ranges when the call is compiled in {$R+} mode.
In Delphi, range checking is only switchable at the procedure level. In Free Pascal, the {$R } directive can be used at the expression level.
Remark: See the note on expression evaluation on 64-bit systems and the consequences for range checking and overflow checking.
Remark: The -CR and -Cr command-line options will activate the range checks globally. They can be switched off locally with the OFF state of the directive.
$REGION : Mark start of collapsible region
The $REGION directive is recognised for Delphi compatibility only. In Delphi it serves to mark the beginning of a collapsible region in the IDE.
$R or $RESOURCE : Include resource
This directive includes a resource in the binary. The argument to this directive is the resource file to include in the binary:
{$R icons.res}
Will include the file icons.res as a resource in the binary. Up to version 2.2.N, resources are supported only for Windows (native resources are used) and for platforms using ELF binaries (linux, BSD). As of version 2.3.1, resources have been implemented for all supported platforms.
The asterisk can be used as a placeholder for the current unit/program filename:
unit myunit;
{$R *.res}
will include myunit.res.
$SATURATION : Saturation operations (Intel 80x86 only)
This works only on the intel compiler, and MMX support must be on ({$MMX +}) for this to have any effect. See the section on saturation support (section Intel MMX support) for more information on the effect of this directive.
$SAFEFPUEXCEPTIONS Wait when storing FPU values on Intel x86
This Boolean directive controls the generation of code to store FPU values. If set ON, the compiler inserts an FWAIT opcode after storing a floating point value. This ensures that any errors are reported immediately. The generated code is slower, but errors are reported at the location where the instruction was executed
$SCOPEDENUMS Control use of scoped enumeration types
The boolean $SCOPEDENUMS directive controls how enumeration type values are inserted in the symbol tables. The enumeration values are always inserted in a scoped manner.
In its default state (OFF) the enumeration values are additionally inserted directly in the symbol table of the current scope. That means that the following 2 assignments are valid:
{$SCOPEDENUMS OFF}
Type
TMyEnum = (one,two,three);
Var
A : TMyEnum;
begin
A:=one;
A:=TMyEnum.one;
end.
If the directive is set to ON then the enumeration values are not inserted in the global scope.
This means the assignment must be made as follows:
{$SCOPEDENUMS ON}
Type
TMyEnum = (one,two,three);
Var
A : TMyEnum;
begin
A:=TMyEnum.one;
// The following will give an error
// A:=one;
end.
i.e. in the ON state of the directive, the value must always be prefixed with the type name.
$SETC : Define and assign a value to a symbol
In MACPAS mode, this directive can be used to define compiler symbols. It is an alternative to the $DEFINE directive for macros. It is supported for compatibility with existing macOSPascal compilers. It will define a symbol with a certain value (called a compiler variable expression).
The expression syntax is similar to expressions used in macros, but the expression must be evaluated at compile-time by the compiler. This means that only some basic arithmetic and logical operators can be used, and some extra possibilities such as the TRUE,FALSE and UNDEFINED operators:
{$SETC TARGET_CPU_PPC := NOT UNDEFINED CPUPOWERPC}
{$SETC TARGET_CPU_68K := NOT UNDEFINED CPUM68K}
{$SETC TARGET_CPU_X86 := NOT UNDEFINED CPUI386}
{$SETC TARGET_CPU_MIPS := FALSE}
{$SETC TARGET_OS_UNIX := (NOT UNDEFINED UNIX) AND (UNDEFINED DARWIN)}
The := assignment symbol may be replaced with the = symbol.
Note that this command works only in MACPAS mode, but independent of the -Sm command line option or {$MACRO } directive.
$S : Stack checking
The {$S+} directive tells the compiler to generate stack checking code. This generates code to check if a stack overflow occurred, i.e. to see whether the stack has grown beyond its maximally allowed size. If the stack grows beyond the maximum size, then a run-time error is generated, and the program will exit with exit code 202.
Specifying {$S-} will turn generation of stack-checking code off.
The command line compiler switch -Ct has the same effect as the {$S+} directive.
By default, no stack checking is performed.
Remark: Stack checking can only be used to provide help during debugging, to try and track routines that use an excessive amount of local memory. It is not intended and cannot be used to actually safely handle such errors. It does not matter whether the error handling is through exception handling or otherwise.
When a stack error occurs, this is a fatal error and the application cannot be kept running correctly, neither in a production environment, nor under debugging.
$STOP : Generate fatal error message
The following code
{$STOP This code is erroneous !}
will display an error message when the compiler encounters it. The compiler will immediately stop the compilation process.
It has the same effect as the {$FATAL} directive.
$STRINGCHECKS : Ignored
This directive is recognized for Delphi compatibility, but is currently ignored. In Delphi, it controls the generation of code that checks the sanity of string variables and arguments.
$T or $TYPEDADDRESS : Typed address operator (@)
In the {$T+} or {$TYPEDADDRESS ON} state, the @ operator, when applied to a variable, returns a result of type ^T, if the type of the variable is T. In the {$T-} state, the result is always an untyped pointer, which is assignment compatible with all other pointer types. This directive is equivalent to the -Sy command-line option.
For example, the following code will not compile:
{$T+}
Var
I : Integer;
P : PChar;
begin
P:=@I;
end.
The compiler will give a type mismatch error:
testt.pp(8,6) Error: Incompatible types: got "^SmallInt" expected "PChar"
By default however, the address operator returns an untyped pointer.
$UNDEF or $UNDEFC : Undefine a symbol
The directive
{$UNDEF name}
un-defines the symbol name if it was previously defined. Name is case insensitive.
In Mac Pascal mode, $UNDEFC is equivalent to $UNDEF, and is provided for Mac Pascal compatibility.
$V or $VARSTRINGCHECKS : Var-string checking
The {$VARSTRINGCHECKS } determines how strict the compiler is when checking string type compatibility for strings passed by reference. When in the + or ON state, the compiler checks that strings passed as parameters are of the same string type as the declared parameters of the procedure.
By default, the compiler assumes that all short strings are type compatible. That is, the following code will compile:
Procedure MyProcedure(var Arg: String[10]);
begin
Writeln('Arg ',Arg);
end;
Var
S : String[12];
begin
S:='123456789012';
Myprocedure(S);
end.
The types of Arg and S are strictly speaking not compatible: The Arg parameter is a string of length 10, and the variable S is a string of length 12: The value will be silently truncated to a string of length 10.
In the {$V+} state, this code will trigger a compiler error:
testv.pp(14,16) Error: string types doesn't match, because of $V+ mode
Note that this is only for strings passed by reference, not for strings passed by value.
$W or $STACKFRAMES : Generate stackframes
The {$W} switch directive controls the generation of stackframes. In the ON state, the compiler will generate a stackframe for every procedure or function.
In the OFF state the compiler will omit the generation of a stackframe if the procedure or function satisfies the following conditions:
it has no parameters.
it has no local variables.
it is not an
assemblerprocedure, i.e., it must not have aasm …end;block.it is not a constructor or destructor.
The stack frame will be omitted only if all these conditions are satisfied.
$WAIT : Wait for enter key press
If the compiler encounters a
{$WAIT}
directive, it will resume compiling only after the user has pressed the enter key. If the generation of info messages is turned on, then the compiler will display the following message:
Press <return> to continue
before waiting for a keypress.
Remark: This may interfere with automatic compilation processes. It should be used only for compiler debugging purposes.
$WARN : Control emission of warnings
This directive allows to selectively turn on or off the emission of warnings. It takes the following form
{$WARN IDENTIFIER ON}
{$WARN IDENTIFIER OFF}
{$WARN IDENTIFIER +}
{$WARN IDENTIFIER -}
{$WARN IDENTIFIER ERROR}
ON or + turns on emission of the warning. The OFF or - values suppress the warning. ERROR promotes the warning to an error, and the compiler will treat it as such.
The IDENTIFIER is the name of a warning message. The following names are recognized:
- CONSTRUCTING_ABSTRACT
-
Constructing an instance of a class with abstract methods.
- IMPLICIT_VARIANTS
-
Implicit use of the
variantsunit. - NO_RETVAL
-
Function result is not set.
- SYMBOL_DEPRECATED
-
Deprecated symbol.
- SYMBOL_EXPERIMENTAL
-
Experimental symbol
- SYMBOL_LIBRARY
-
Not used.
- SYMBOL_PLATFORM
-
Platform-dependent symbol.
- SYMBOL_UNIMPLEMENTED
-
Unimplemented symbol.
- UNIT_DEPRECATED
-
Deprecated unit.
- UNIT_EXPERIMENTAL
-
Experimental unit.
- UNIT_LIBRARY
- UNIT_PLATFORM
-
Platform dependent unit.
- UNIT_UNIMPLEMENTED
-
Unimplemented unit.
- ZERO_NIL_COMPAT
-
Converting 0 to NIL
- IMPLICIT_STRING_CAST
-
Implicit string type conversion
- IMPLICIT_STRING_CAST_LOSS
-
Implicit string typecast with potential data loss from "$1" to "$2"
- EXPLICIT_STRING_CAST
-
Explicit string type conversion
- EXPLICIT_STRING_CAST_LOSS
-
Explicit string typecast with potential data loss from "$1" to "$2"
- CVT_NARROWING_STRING_LOST
-
Unicode constant cast with potential data loss
- INTF_RAISE_VISIBILITY
-
Using an interface raises the visibility of the implementation of a method. (this is an error for the JVM bytecode backend)
Besides the above text identifiers, the identifier can also be a message number. The numbers of the messages are displayed when the -vq command-line option is used.
$WARNING : Generate warning message
If the generation of warnings is turned on, through the -vw command line option or the {$WARNINGS ON} directive, then
{$WARNING This is dubious code}
will display a warning message when the compiler encounters it.
$WARNINGS : Emit warnings
{$WARNINGS ON} switches the generation of warnings on. {$WARNINGS OFF} switches the generation of warnings off. Contrary to the command line option -vw this is a local switch, this is useful for checking parts of your code.
By default, no warnings are emitted.
$Z1, $Z2 and $Z4
This switch is an equivalent of the {$PACKENUM } switch (see section Compiler directives).
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
